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
最后更新于3年前