Number of 1 Bits LeetCode solution in C++

1
class Solution {
2
public:
3
int hammingWeight(uint32_t n) {
4
int ans = 0;
5
while (n != 0) {
6
n = n & (n - 1);
7
ans++;
8
}
9
return ans;
10
}
11
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0