Skip to content

Commit 9c6453e

Browse files
committed
feat: added counting bits algorithm
1 parent 1b5c1b8 commit 9c6453e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

dynamic_programming/counting_bits.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def countBits(num: int):
2+
'''
3+
>>
4+
'''
5+
ones = [0, 1]
6+
anchor = 2
7+
8+
if num < 2:
9+
return ones[:num+1]
10+
11+
while(True):
12+
j = 0
13+
while(j<anchor):
14+
if len(ones) == num+1:
15+
return ones
16+
ones.append(ones[j]+1)
17+
j += 1
18+
19+
anchor = anchor + j
20+
21+
print(countBits(5))

0 commit comments

Comments
 (0)