LC338 - Counting Bits
Problem
Example
Solution
Intuition
def countBits(self, n: int) -> List[int]:
count = []
for i in range(0, n+1):
tmp = format(i, 'b')
subcount = 0
for char in tmp:
if char == '1':
subcount += 1
count.append(subcount)
return countDynamic Programming
Last updated