Skip to content

Commit b87ce6f

Browse files
committed
solved counting bits
1 parent 80316f8 commit b87ce6f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

counting-bits/samthekorean.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# TC : O(nlog(n))
2+
# SC : O(n)
3+
class Solution:
4+
def countBits(self, n: int) -> List[int]:
5+
count = 0
6+
ans = []
7+
8+
for i in range(n + 1):
9+
while i > 0:
10+
count += i % 2
11+
i = i // 2
12+
ans.append(count)
13+
count = 0
14+
15+
return ans

0 commit comments

Comments
 (0)