Day 8 Task:
→ 338. Counting Bits:
→ Leetcode: https://leetcode.com/problems/counting-bits/
Solutions:
Please review all the solutions and try implementing on your own if you haven’t gotten it.
class Solution:
def countBits(self, n: int) -> List[int]:
dp = [0] * (n + 1)
offset = 1
for i in range(1, n + 1):
if offset * 2 == i:
offset = i
dp[i] = 1 + dp[i - offset]
return dp