Skip to content

Commit f189d0a

Browse files
committed
191 Number of 1 Bits update solution
1 parent e6d4e0d commit f189d0a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

number-of-1-bits/doh6077.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
class Solution:
22
def hammingWeight(self, n: int) -> int:
3-
binary_num = format(n, 'b')
4-
return binary_num.count('1')
3+
ans = 0
4+
while n != 0:
5+
ans += 1
6+
n = n & ( n-1)
7+
return ans

0 commit comments

Comments
 (0)