Skip to content

Commit ecb817a

Browse files
committed
feat: add number of 1 bits solution
1 parent 480b937 commit ecb817a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

number-of-1-bits/dm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def hammingWeight(self, n: int, acc: int = 0) -> int:
3+
if n == 0:
4+
return acc
5+
6+
return self.hammingWeight(n // 2, acc + n % 2)

0 commit comments

Comments
 (0)