python using xor


  • 0
    U
    class Solution(object):
        def findComplement(self, num):
            """
            :type num: int
            :rtype: int
            """
            bit_len = len('{:b}'.format(num))
            ones = 2 ** bit_len - 1
            xor = ones ^ num
            return xor
    

Log in to reply
 

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