Skip to content

Commit 5f65c66

Browse files
committed
Number of 1 Bits 문제 풀이
1 parent f041548 commit 5f65c66

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

number-of-1-bits/ymir0804.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.List;
2+
3+
class Solution {
4+
public int hammingWeight(int n) {
5+
int result = 1;
6+
if(n <= 2) {
7+
return result;
8+
}
9+
while (true) {
10+
if (n % 2 == 1) {
11+
result++;
12+
}
13+
n /= 2;
14+
if(n <= 2) {
15+
break;
16+
}
17+
}
18+
return result;
19+
}
20+
}

0 commit comments

Comments
 (0)