fbd4ffd0717b

关注

leetcode - Number of 1 Bits

fbd4ffd0717b

关注

阅读 50

2023-06-29


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


相关推荐

云卷云舒xj

[LeetCode]Number of 1 Bits

云卷云舒xj 119 0 0

干自闭

LeetCode: 191. Number of 1 Bits

干自闭 65 0 0

Jonescy

191。Number of1 Bits

Jonescy 48 0 0

爱情锦囊

191. Number of 1 Bits

爱情锦囊 64 0 0

ixiaoyang8

191. Number of 1 Bits*

ixiaoyang8 60 0 0

半夜放水

[leetcode] 693. Binary Number with Alternating Bits

半夜放水 28 0 0

爪哇驿站

【leetcode_easy_sort】1356. Sort Integers by The Number of 1 Bits

爪哇驿站 68 0 0

做个橙梦

【Leetcode_easy】693. Binary Number with Alternating Bits

做个橙梦 25 0 0

半秋L

LINUX编译OPENJDK:The tested number of bits in the target (0) differs from the number of bits expected

半秋L 116 0 0

yongxinz

【Leetcode_easy】762. Prime Number of Set Bits in Binary Representation

yongxinz 29 0 0

精彩评论(0)

0 0 举报