public int[] countBits(int num) {

```
int dp[] = new int[num + 1];
for (int i = 1 ; i <= num ; i++) {
if (i % 2 == 0) {
dp[i] = dp[i/2];//even
} else {
dp[i] = dp[i-1] + 1;//odd
}
}
return dp;
```

}