191 numbers of 1 bits
2017-11-20 本文已影响0人
larrymusk
n&(n-1) 每次清掉一个1
int hammingWeight(uint32_t n) {
int count = 0;
while(n){
n = n&(n-1);
count++;
}
return count;
}
n&(n-1) 每次清掉一个1
int hammingWeight(uint32_t n) {
int count = 0;
while(n){
n = n&(n-1);
count++;
}
return count;
}