Python3 代码
class Solution(object):
def NumberOf1(self,n):
"""
:type n: int
:rtype: int
"""
re = []
t = abs(n)
while t :
re.append(t % 2)
t //= 2
if n >= 0:
return re.count(1)
else:
num = 32 - len(re)
return num + re.count(1)