Simple Python Solution


  • 0
    M
    def findComplement(self, num):
            """
            :type num: int
            :rtype: int
            """
            s = ''
            while num:
                s += '0' if num & 1 else '1'
                num >>= 1
            return int(''.join(list(reversed(s))), 2)
    

Log in to reply
 

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