easy
Counting Bits
Given an integer n, return an array where entry i (for 0 ≤ i ≤ n) is the number of 1 bits in the binary representation of i. Aim for linear total time.
Constraints
- 0 ≤ n ≤ 10^5
Examples
in: n = 5
out: [0,1,1,2,1,2]
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.