python implementation


  • 0
    S

    class Solution(object):
    def findComplement(self, num):
    """
    :type num: int
    :rtype: int
    """
    tmp = num
    bit_num = 0
    while (tmp != 0):
    bit_num += 1
    tmp = tmp >> 1

        return ((~num) & (2**bit_num - 1))

Log in to reply
 

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