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.
Try to solve it in O(n) time and without using the built-in popcount function.
n = 2[0, 1, 1]n = 5[0, 1, 1, 2, 1, 2]0 <= n <= 10^5Expected time complexity: O(n)Run your code to see results
Use Cmd+Enter to run