Yet another simple Python solution


  • 0
    S
    class Solution(object):
        def findComplement(self, num):
            """
            :type num: int
            :rtype: int
            """
            num = bin(num)[2:]
            result = ''
            for digit in num:
                result += str(int(not int(digit, 2)))
            return int(result, 2)
    

Log in to reply
 

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