2023-09-24 09:51:48 +0000 UTC

Number of 1 Bits

Code

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