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;
}
本文标题:191 numbers of 1 bits
本文链接:https://www.haomeiwen.com/subject/fhnbvxtx.html
网友评论