Skip to content

Commit 8a309dc

Browse files
committed
Merge pull request SocialfiPanda#9 from resorcap/master
Add `Number of 1 Bits`
2 parents dcd640a + 2daa9b6 commit 8a309dc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Number of 1 Bits.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def hammingWeight(self, n):
3+
count = 0
4+
while n:
5+
count += 1
6+
n = (n - 1) & n
7+
return count

0 commit comments

Comments
 (0)