class Solution {
public:
// 除k取余法求二进制 (暴力)
vector<int> countBits(int n) {
vector<int> ans;
for(int i=0;i<=n;i++){
int t=i;
int count=0;
while(t!=0){
if(t%2==1){
count++;
}
t/=2;
}
ans.push_back(count);
}
return ans;
}
};
标签:countBits,338,比特,int,计数,vector
From: https://www.cnblogs.com/mengfengguang/p/16794088.html