leetcode/0191_number-of-1-bits/python3/shift.py

10 lines
198 B
Python
Raw Normal View History

2022-04-25 21:06:21 +00:00
class Solution:
def hammingWeight(self, n: int) -> int:
count = 0
while n:
count += 1 if n & 1 == 1 else 0
n >>= 1
return count