class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
while (n) {
res++;
// erase the left-most 1
n &= n - 1;
}
// return __builtin_popcount(n);
return res;
}
};
class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
while (n) {
res += n & 1;
n >>= 1;
}
return res;
}
};