We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c8ca38e commit 43a2477Copy full SHA for 43a2477
src/main/java/com/fishercoder/solutions/_191.java
@@ -7,6 +7,11 @@ public static class Solution1 {
7
* Doing bitwise AND operation between n and n-1 will always flip the least significant 1 bit in n to zero
8
* example run for the above editorial solution: input 5, n will be 5&4 and becomes 4,
9
* then in the next run, n will become 4&3 which is 0, thus exit the while loop.
10
+ *
11
+ * e.g. 5 in binary format: 101
12
+ * 4 in binary format: 100
13
+ * so 5 AND 4 becomes 100, it's the least significant 1-bit in n always maps to a 0-bit in n - 1
14
+ * so n ANDs with n - 1, will just set the least significant 1-bit in n to be zero and all other bits remain unchanged
15
*/
16
public int hammingWeight(int n) {
17
int bits = 0;
0 commit comments