Skip to content

Commit

Permalink
Create 338-Counting-Bits.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neetcode-gh authored Dec 26, 2021
1 parent e46ad16 commit b7f9333
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 338-Counting-Bits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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

0 comments on commit b7f9333

Please sign in to comment.