1 line python


  • 0
    V
    class Solution(object):
        def findComplement(self, num):
            """
            :type num: int
            :rtype: int
            """
            return (1 << num.bit_length()) - 1 ^ num
    

    bit negation equals bit exclusive or 1


Log in to reply
 

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