Number Complement

Problem Id: 476 Difficulty: Easy


Intuition

Solution


class Solution:
    def findComplement(self, num: int) -> int:
        mask = 1
        while mask < num:
            mask = (mask << 1) + 1
        # print(mask)
        return mask ^ num