Skip to content

Commit e7ad31f

Browse files
committed
adding number of 1 bits
1 parent b0a7b83 commit e7ad31f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

number-of-1-bits/daiyongg-kim.py

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

0 commit comments

Comments
 (0)