191. Number of 1 Bits (Easy) - TengnanYao/daily_leetcode GitHub Wiki

class Solution(object):
    def hammingWeight(self, n):
        """
        :type n: int
        :rtype: int
        """
        result = 0
        for _ in range(32):
            result += n & 1
            n >>= 1
        return result