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

10 lines
198 B
Python

class Solution:
def hammingWeight(self, n: int) -> int:
count = 0
while n:
count += 1 if n & 1 == 1 else 0
n >>= 1
return count