leetcode题解-1的个数
程序员文章站
2024-03-24 09:50:22
...
class Solution {
public:
int hammingWeight(uint32_t n)
{
int count=0;
int mask=1;
for(int i=0;i<32;i++)
{
if(n&&mask!=0)
count++;
mask<<1;
}
return count;
}
};