leetcode - Number of 1 Bits

来源:互联网 发布:软件成果展板板 编辑:程序博客网 时间:2024/05/18 03:24

https://leetcode.com/problems/number-of-1-bits/

bit manipulation

class Solution(object):    def hammingWeight(self, n):        """        :type n: int        :rtype: int        """        res = 0        while n:            res += n & 1            n >>= 1        return res
0 0