Skip to content

Commit a86efc5

Browse files
committed
feat : number-of-1-bits
1 parent d380482 commit a86efc5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

number-of-1-bits/ekgns33.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int hammingWeight(int n) {
3+
int curN = n;
4+
int cnt = 0;
5+
while(curN > 0) {
6+
if(curN %2 == 1) {
7+
cnt++;
8+
}
9+
curN /= 2;
10+
}
11+
return cnt;
12+
}
13+
}
14+
/**
15+
16+
1 2 3 4 5 6 7 8 9 10 11
17+
0 1 2 1 2 2 3 1 2 2 3
18+
19+
*/

0 commit comments

Comments
 (0)