Counting Bits
Problem statement
For every integer from 0 through n, return the number of set bits in its binary representation.
Function
countBits(n: int) → int[]Examples
Example 1
n = 0return = [0]Case 1 exercises the documented deterministic contract.
Example 2
n = 1return = [0,1]Case 2 exercises the documented deterministic contract.
Example 3
n = 2return = [0,1,1]Case 3 exercises the documented deterministic contract.
Constraints
0 <= n <= 1000000.