public class Solution {
public int[]
countBits(
int num) {
List<Integer> list =
new ArrayList<>();
for(
int i=
0;i<=num;i++) {
list.add(cacuate(i));
}
int[] res =
new int[list.size()];
int j=
0;
for(Integer i: list) {
res[j++] = i;
}
return res;
}
public int cacuate(
int n) {
int sum =
0;
while(n!=
0) {
if(n%
2 ==
1) {
sum+=
1;
}
n=n/
2;
}
return sum;
}
}
转载请注明原文地址: https://ju.6miu.com/read-25399.html