Skip to content

Commit a2d1621

Browse files
committed
[LC] feat: number-of-bits
1 parent 6d1ee5a commit a2d1621

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

number-of-1-bits/hajunyoo.py

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

0 commit comments

Comments
 (0)