Skip to content

Commit 173cf0f

Browse files
author
jinbeom
committed
Counting Bits Solution
1 parent cd5accd commit 173cf0f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

counting-bits/kayden.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 시간복잡도: O(N)
2+
# 공간복잡도: O(N)
3+
class Solution:
4+
5+
def countBits(self, n: int) -> List[int]:
6+
ans = [0 for _ in range(n + 1)]
7+
for num in range(1, n + 1):
8+
ans[num] = ans[num >> 1] + (num & 1)
9+
10+
return ans

0 commit comments

Comments
 (0)