Q191. Number of 1 Bits
分析:
C++代码
class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
while(n){
n &= n-1;
res++;
}
return res;
}
};Last updated
class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
while(n){
n &= n-1;
res++;
}
return res;
}
};Last updated