public class Solution {
public int[] countBits(int num) {
int n[] = new int[num+1];
int base = 1;
n[0] = 0;
for(int i=1, t=0; i<=num; i++, t++) {
if(i == base) {
t = 0;
base *= 2;
}
n[i] = n[t] + 1;
}
return n;
}
}
网友评论