class Solution {
public:
int hammingWeight(uint32_t n) {
int count = 0;
while (n)
{
if (n % 2 == 1)
{
count ++;
}
n = n / 2;
}
return count ;
}
};
剑指offer--面试题15. 二进制中1的个数
最新推荐文章于 2021-04-26 15:44:53 发布