Skip to content

Commit 791072c

Browse files
Refactor : Number of 1 Bits
1 parent 3a7c42b commit 791072c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

combination-sum/printjin-gmailcom.py

Whitespace-only changes.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
class Solution:
22
def hammingWeight(self, n):
3-
return bin(n).count('1')
3+
cnt = 0
4+
while n > 0:
5+
cnt += n % 2
6+
n //= 2
7+
return cnt

0 commit comments

Comments
 (0)