【leetcode❤python】191. Number of 1 Bits

#-*- coding: UTF-8 -*-
class Solution(object):
    def hammingWeight(self, n):
        if n<=0:return n
        mid=[]
        while True:
            if n==0:break
            n,mod=divmod(n,2)
            mid.append(mod)
        mid.reverse()
        return mid.count(1)

sol=Solution()
print sol.hammingWeight(11)

上一篇:C# 多个个Dictionary合并更优雅的写法


下一篇:linux OpenOffice