Skip to content

Commit e713338

Browse files
authored
Create 338-Counting-Bits.py
1 parent de87b63 commit e713338

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

338-Counting-Bits.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def countBits(self, n: int) -> List[int]:
3+
dp = [0] * (n + 1)
4+
offset = 1
5+
6+
for i in range(1, n + 1):
7+
if offset * 2 == i:
8+
offset = i
9+
dp[i] = 1 + dp[i - offset]
10+
return dp

0 commit comments

Comments
 (0)