221. Counting Bits
EasyDynamic Programming
Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.
Examples
Input: 2
Output: [0,1,1]
Explanation: 0 -> 0b0 (0 ones), 1 -> 0b1 (1 one), 2 -> 0b10 (1 one).
Constraints
- 0 <= n <= 10^5
Loading...
Run checks all cases above. Submit evaluates all test cases.