标签:view page bb10 href flag 个数 interview sig 链接
class Solution {
public:
int NumberOf1(int n) {
unsigned int flag=1,sum=0;
for(int i=0;i<32;++i){
sum+=flag&n?1:0;
flag<<=1;
}
return sum;
}
};
class Solution {
public:
int NumberOf1(int n) {
unsigned int sum=0;
while(n!=0){
n=n&(n-1);
sum++;
}
return sum;
}
};
标签:view page bb10 href flag 个数 interview sig 链接
原文地址:https://www.cnblogs.com/chanceYu/p/12764174.html