Python solution: easy to understand


  • 0
    J
    def findComplement(self, num):
        """
        :type num: int
        :rtype: int
        """
        a = bin(num)[2:]
        c = int('1'*len(a))
        return int(str(c - int(a)), 2)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.