Skip to content

Commit c2f15ec

Browse files
committed
Solved leetcode 338
1 parent dd178be commit c2f15ec

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: 338/338.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def countBits(self, n: int) -> List[int]:
3+
counter = 0
4+
highestPower = 1
5+
ans = [0]*(n + 1)
6+
7+
for i in range(1, n + 1):
8+
if(i == highestPower):
9+
highestPower *= 2
10+
counter = 0
11+
ans[i] = ans[counter] + 1
12+
counter += 1
13+
14+
print(i, highestPower, counter)
15+
16+
return ans
17+
18+

0 commit comments

Comments
 (0)