191. Number of 1 Bits(bit)

# Easy

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

Last updated