Skip to content

Commit 6b865f9

Browse files
committed
feat: solve number of 1 bits
1 parent 10b20a4 commit 6b865f9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

number-of-1-bits/GangBean.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int hammingWeight(int n) {
3+
int count = 0;
4+
while (n >= 1) {
5+
count += n % 2;
6+
n /= 2;
7+
}
8+
return count;
9+
}
10+
}
11+

0 commit comments

Comments
 (0)