Skip to content

Commit b06a76b

Browse files
add: num of 1 bit
1 parent ea58a3b commit b06a76b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

number-of-1-bits/YoungSeok-Choi.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// NOTE: 10진수를 2 진수로 변환
2+
// O(logN)
3+
class Solution {
4+
public int hammingWeight(int n) {
5+
int oneCnt = 0;
6+
7+
while(n >= 1) {
8+
if((n % 2) == 1) {
9+
oneCnt++;
10+
}
11+
n = n / 2;
12+
}
13+
14+
return oneCnt;
15+
}
16+
}

0 commit comments

Comments
 (0)