Skip to content

Commit 5d5ebd4

Browse files
committed
[WEEK 03] number of 1 bits
1 parent dabcb5f commit 5d5ebd4

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

number-of-1-bits/essaysir.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int hammingWeight(int n) {
3+
// 이진수로 바꾸고, 1 이 몇개 있는 지 파악한다.
4+
return Integer.bitCount(n);
5+
6+
// 추가 풀이.
7+
// String ans = Integer.toBinaryString(n).replace("0","");
8+
// return ans.length();
9+
}
10+
}
11+

0 commit comments

Comments
 (0)