public class Solution {

public int[] countBits(int num) {

int[] nums = new int[num+1];

nums[0]=0;

int t=1;

while(t<=num){

nums[t]=1;

t*=2;

}

int index=2;

for(int j=2;j<num+1;j++){

if(nums[j]!=0) {

index=j;

continue;

}

nums[j]=nums[j-index]+1;

}

return nums;

}

}