191. Number of 1 Bits
class Solution:
def hammingWeight(self, n: int) -> int:
ans = 0
while n:
ans += n & 1
n = n >> 1
return ansclass Solution:
def hammingWeight(self, n: int) -> int:
ans = 0
while n:
n = n & (n - 1)
ans += 1
return ansLast updated