Skip to content

Commit 0f38dc2

Browse files
Completed
1 parent bc5c615 commit 0f38dc2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

21 Misc/15 Count all set bits.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution{
2+
public int hammingWeight(int n) {
3+
int count = 0;
4+
for(int i=0;i<32;i++){
5+
if((n&1)==1)
6+
count++;
7+
n>>>=1;
8+
}
9+
return count;
10+
}
11+
public int helper(int n)
12+
{
13+
int result = 0;
14+
for(int i=0;i<=n;i++){
15+
result += hammingWeight(i);
16+
}
17+
return result;
18+
}
19+
}

0 commit comments

Comments
 (0)