#-*- 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)
相关文章
- 01-16Leetcode练习(Python):数组类:第84题:给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。 求在该柱状图中,能够勾勒出来的矩形的最大面积。
- 01-16【刷题-LeetCode】191 Number of 1 Bits
- 01-16【Leetcode_easy】762. Prime Number of Set Bits in Binary Representation
- 01-16191. Number of 1 Bits
- 01-16LeetCode 191. Number of 1 Bits
- 01-16[Swift]LeetCode693. 交替位二进制数 | Binary Number with Alternating Bits
- 01-16【Leetcode】191. Number of 1 Bits(二进制数)(面试必备)
- 01-161356. Sort Integers by The Number of 1 Bits
- 01-16LeetCode - 191. Number of 1 Bits
- 01-161356. Sort Integers by The Number of 1 Bits