package pep.Day81;
import java.util.Scanner;
public class Kernighans_Algorithm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans = 0;
while (n > 0) {
int rmsbm = n & -n;
ans++;
n -= rmsbm;
}
System.out.println(ans);
}
}
Thursday, May 19, 2022
Subscribe to:
Post Comments (Atom)
Diagonal Traversal
eg. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Output: 1 6 11 16 2 7 12 3 8 4 Approach:...
-
Why appending to a string in Java can become O(n²). 🔴 Problem: Strings are immutable in Java When you do: String s = "" ; s ...
-
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/ Given the sorted rotated array nums of unique elements, retu...
-
https://leetcode.com/problems/koko-eating-bananas/description/ Piles: 📦 📦 📦 📦 → 4 piles Hours: ⏰ ⏰ ⏰ ⏰ ⏰ ⏰ → 6 h...


No comments:
Post a Comment