0
点赞
收藏
分享

微信扫一扫

leetcode - Number of 1 Bits

fbd4ffd0717b 2023-06-29 阅读 50


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 条评论