class Solution {
public:
int NumberOf1(int n) {
int c = 0;
while(n)
{
n = n & (n - 1);
c++;
}
return c;
}
};
剑指offer:二进制中1的个数
最新推荐文章于 2015-12-15 00:30:54 发布
class Solution {
public:
int NumberOf1(int n) {
int c = 0;
while(n)
{
n = n & (n - 1);
c++;
}
return c;
}
};