【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)