For a whole number n, build an array ans that has n + 1 entries. For each i from 0 to n, the entry ans[i] tells how many 1 bits the binary form of i has. Return ans.
Examples
Example 1:
Input: n = 4
Output: [0,1,1,2,1]
Explanation: 0 is 0, 1 is 1, 2 is 10, 3 is 11, 4 is 100. The counts of 1 bits are 0, 1, 1, 2, 1.
Example 2:
Input: n = 8
Output: [0,1,1,2,1,2,2,3,1]
Explanation: 8 is 1000 in binary and has one 1 bit. 7 is 111 and has three.
Example 3:
Input: n = 3
Output: [0,1,1,2]
Explanation: 0, 1, 10 and 11 have 0, 1, 1 and 2 bits that are 1.