Counting Bits
Input:
2
Output:
[0,1,1]Input:
5
Output:
[0,1,1,2,1,2]Last updated
Input:
2
Output:
[0,1,1]Input:
5
Output:
[0,1,1,2,1,2]Last updated
class Solution:
def countBits(self, num: int) -> List[int]:
"""
:type num: int
:rtype: List[int]
"""
p = [0]*(num+1)
for i in range(1,num+1):
p[i] =p[i&(i-1)] + 1
return p