
int hammingWeight(uint32_t n) {
int cnt = 0;
while(n){
++cnt;
n&=(n-1);//将最右边的1变成0
}
return cnt;
}
该博客围绕用C++计算位1的个数展开,虽未给出具体内容,但核心是此信息技术相关的计算问题。

int hammingWeight(uint32_t n) {
int cnt = 0;
while(n){
++cnt;
n&=(n-1);//将最右边的1变成0
}
return cnt;
}
591
245
200

被折叠的 条评论
为什么被折叠?