题目
https://leetcode-cn.com/problems/number-of-1-bits/
分析
位运算
代码实现
class Solution(object):
def hammingWeight(self, n):
“”"
:type n: int
:rtype: int
“”"
count=0
while n:
count += n&1
n >>=1
return count
https://leetcode-cn.com/problems/number-of-1-bits/
位运算
class Solution(object):
def hammingWeight(self, n):
“”"
:type n: int
:rtype: int
“”"
count=0
while n:
count += n&1
n >>=1
return count