Skip to content

Commit fd63601

Browse files
committed
feat: number-of-1-bits
1 parent 97978b3 commit fd63601

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

number-of-1-bits/minji-go.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* <a href="https://leetcode.com/problems/number-of-1-bits/">week03-2.number-of-1-bits</a>
3+
* <li>Description: returns the number of set bits in its binary representation</li>
4+
* <li>Topics: Divide and Conquer, Bit Manipulation </li>
5+
* <li>Time Complexity: O(logN), Runtime 0ms </li>
6+
* <li>Space Complexity: O(1), Memory 41.95MB </li>
7+
*/
8+
class Solution {
9+
public int hammingWeight(int n) {
10+
int count = 0;
11+
while(n != 0) {
12+
n &= (n-1);
13+
count++;
14+
}
15+
return count;
16+
}
17+
}

0 commit comments

Comments
 (0)