191 Number of 1 Bits

333 ワード

原題リンク:Number of 1 Bits
Pythonの強さを感じてみよう!!!コードは次のとおりです.
class Solution:
    # @param n, an integer
    # @return an integer
    def hammingWeight(self, n):
        count = 0
        num = list(bin(n))
        for bit in num:
            if bit is '1':
                count += 1
        return count