Skip to content

Commit 0e116ed

Browse files
committed
number of 1 bits solved
1 parent 9aaaf5f commit 0e116ed

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

number-of-1-bits/sora0319.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int hammingWeight(int n) {
3+
int cnt = 0;
4+
String binary = Integer.toBinaryString(n);
5+
6+
for(int i = 0; i < binary.length(); i++){
7+
if(binary.charAt(i) == '1') cnt++;
8+
}
9+
return cnt;
10+
}
11+
}
12+

0 commit comments

Comments
 (0)