Easy
DP
Bit Manipulation
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
.
Example 1:
Example 2:
Constraints:
n
<= 105Follow up:
O(n log n)
. Can you do it in linear time O(n)
and possibly in a single pass?__builtin_popcount
in C++)?JimSep 1, 2023
Yen-Chi ChenFri, Sep 1, 2023
Jerry WuFir, Sep 1, 2023