169. Counting Bits

Given a non-negative integer n. Return an array of length n + 1, where ans[i] is the number of set bits in the number i.
Example 1
Input: n = 5
Output: [0,1,1,2,1,2]
Explanation: Bit count array for numbers 0 through 5.
Example 2
Input: n = 2
Output: [0,1,1]
Explanation: For numbers 0, 1, and 2 the bit counts are 0, 1, and 1.
bit manipulationeasy
JavaScript
Loading...
Line 1, Char 1