Skip to content

Commit 8476fc0

Browse files
committed
feat: number-of-1-bits
1 parent 7067abc commit 8476fc0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/**
2-
* <a href="https://leetcode.com/problems/number-of-1-bits/">week03-2.number-of-1-bits</a>
2+
* <a href="https://leetcode.com/problems/number-of-1-bits/">week8-1.number-of-1-bits</a>
33
* <li>Description: returns the number of set bits in its binary representation</li>
44
* <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>
5+
* <li>Time Complexity: O(K), Runtime 0ms </li>
6+
* <li>Space Complexity: O(1), Memory 40.57MB </li>
77
*/
8+
89
class Solution {
910
public int hammingWeight(int n) {
1011
int count = 0;
11-
while(n != 0) {
12-
n &= (n-1);
12+
while (n != 0) {
13+
n = n & (n - 1);
1314
count++;
1415
}
1516
return count;

0 commit comments

Comments
 (0)