int* countBits(int num, int* returnSize) {

if (num < 0 ) {

return NULL;

}

```
int *dp = (int *) malloc(sizeof(int)* (num + 1));
*returnSize = num + 1;
dp[0] = 0;
for (int i =1; i <= num; i++) {
if (i & 1) {
dp[i] = 1 + dp[i - 1];
} else {
dp [i] = dp[i >> 1];
}
}
return dp;
```

}