straight method to solve the problem


  • 0
    D

    class Solution(object):
    def findComplement(self, num):
    """
    :type num: int
    :rtype: int
    """
    temp = bin(num)
    result ='0b'
    for i,ch in enumerate(temp[2:]):
    if ch == '1':
    result += '0'
    elif ch =='0':
    result += '1'
    else:
    result += ch
    result = (int(result,2))
    return abs(result)


Log in to reply
 

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