int hammingWeight(uint32_t n)
{
int res = 0;
while(n)
{
n &= n - 1;
++res;
}
return res;
}
统计bit 1的个数
最新推荐文章于 2024-05-12 10:36:52 发布
int hammingWeight(uint32_t n)
{
int res = 0;
while(n)
{
n &= n - 1;
++res;
}
return res;
}