标签:sig tle 位置 sub cpp 进制 int 题目 表示
class Solution {
public:
int NumberOf1(int n) {
unsigned int flag=1;
int count=0;
while(flag!=0){
if(n&flag){
count++;
}
flag=flag<<1;
}
return count;
}
};
class Solution {
public:
int NumberOf1(int n) {
int count=0;
while(n!=0){
count++;
n = n & (n-1);
}
return count;
}
};
标签:sig tle 位置 sub cpp 进制 int 题目 表示
原文地址:https://www.cnblogs.com/fancy-li/p/11612324.html