Skip to content

Commit e4b6553

Browse files
refactor 191
1 parent 0bcda05 commit e4b6553

File tree

1 file changed

+5
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+5
-9
lines changed

src/main/java/com/fishercoder/solutions/_191.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 191. Number of 1 Bits
5-
*
6-
* Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
7-
* For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3.*/
8-
93
public class _191 {
104

115
public static class Solution1 {
12-
/**Doing bitwise AND operation between n and n-1 will always flip the least significant 1 bit in n to zero
13-
example run for the above editorial solution: input 5, n will be 5&4 and becomes 4,
14-
then in the next run, n will become 4&3 which is 0, thus exit the while loop.*/
6+
/**
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+
*/
1511
public int hammingWeight(int n) {
1612
int bits = 0;
1713
while (n != 0) {

0 commit comments

Comments
 (0)