File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 1
1
/**
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>
3
3
* <li>Description: returns the number of set bits in its binary representation</li>
4
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>
5
+ * <li>Time Complexity: O(K ), Runtime 0ms </li>
6
+ * <li>Space Complexity: O(1), Memory 40.57MB </li>
7
7
*/
8
+
8
9
class Solution {
9
10
public int hammingWeight (int n ) {
10
11
int count = 0 ;
11
- while (n != 0 ) {
12
- n &= ( n - 1 );
12
+ while (n != 0 ) {
13
+ n = n & ( n - 1 );
13
14
count ++;
14
15
}
15
16
return count ;
You can’t perform that action at this time.
0 commit comments