Skip to content

Commit ee5a1ec

Browse files
donghyeon95donghyeon95
authored andcommitted
feat: Number of 1 Bits #232
1 parent e30b45e commit ee5a1ec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

number-of-1-bits/donghyeon95.java

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

0 commit comments

Comments
 (0)