Skip to content

Commit a371a2e

Browse files
Solve : Counting Bits
1 parent cb9dd7b commit a371a2e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

counting-bits/printjin-gmailcom.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def countBits(self, n):
3+
ans = [0] * (n + 1)
4+
for i in range(1, n + 1):
5+
ans[i] = ans[i >> 1] + (i & 1)
6+
return ans

0 commit comments

Comments
 (0)