class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
while(n)
{
res++;
n = n&(n-1);
}
return res;
}
};
191 Number of 1 Bits
最新推荐文章于 2023-12-31 14:53:17 发布
class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
while(n)
{
res++;
n = n&(n-1);
}
return res;
}
};