C++ 代码
class Solution {
public:
int hammingWeight(uint32_t n) {
short num=0;
while(n)
{
if(n&1) num++;
n>>=1;
}
return num;
}
};
class Solution {
public:
int hammingWeight(uint32_t n) {
short num=0;
while(n)
{
n&=n-1;
num++;
}
return num;
}
};