Skip to content

Commit db63f49

Browse files
committed
Add number of 1bits Solution - s0ooo0k
1 parent c890830 commit db63f49

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

number-of-1-bits/s0ooo0k.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int hammingWeight(int n) {
3+
/*
4+
* 시간복잡도 O(log n)
5+
*/
6+
int cnt = 0;
7+
while(n!=0) {
8+
if(n%2==1) cnt++;
9+
n = n / 2;
10+
}
11+
return cnt;
12+
}
13+
}
14+

0 commit comments

Comments
 (0)