class Solution {
public:
vector<int> countBits(int num) {
vector<int> v;
if(num == 0){
v.push_back(0);
}
if(num == 1){
v.push_back(0);
v.push_back(1);
}
if(num >= 2){
v.push_back(0);
v.push_back(1);
for(int j = 2;j <= num;j++){
int count = 0;
int i = j;
while(i>0){
i = i&(i-1);
count++;
}
v.push_back(count);
}
}
return v;
}
};
12-28
454
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-05