Skip to content

Commit e46ad16

Browse files
authored
Create 191-Number-of-1-Bits.py
1 parent f87d23d commit e46ad16

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

191-Number-of-1-Bits.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def hammingWeight(self, n: int) -> int:
3+
res = 0
4+
while n:
5+
n &= (n - 1)
6+
res += 1
7+
return res

0 commit comments

Comments
 (0)