原题链接: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