Leetcode 476. Number Complement

原数和二进制全为1的数异或.

class Solution:
    def findComplement(self, num: int) -> int:
        size = len(bin(num)[2:]) - 1
        t = 1
        for _ in range(size):
            t = (t << 1) + 1
        return num ^ t
原文地址:https://www.cnblogs.com/zywscq/p/10708528.html