1009. 十进制整数的反码

https://leetcode-cn.com/problems/complement-of-base-10-integer/

同476. 数字的补数

解法一:

class Solution:
    def bitwiseComplement(self, n: int) -> int:
        height = 0
        for i in range(31):
            if n >= 1 << i:
                height = i
        mask = (1 << (height+1)) - 1
        return n ^ mask

最后更新于