Skip to content

Commit c76f290

Browse files
committed
solve 1
1 parent 2610d48 commit c76f290

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

counting-bits/pmjuu.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
시간 복잡도: O(n)
3+
공간 복잡도: O(n)
4+
'''
5+
from typing import List
6+
7+
8+
class Solution:
9+
def countBits(self, n: int) -> List[int]:
10+
dp = [0] * (n + 1)
11+
12+
for i in range(1, n + 1):
13+
dp[i] = dp[i >> 1] + (i & 1)
14+
15+
return dp

0 commit comments

Comments
 (0)