Python O(log(size(int)) Solution


  • 0
    L
    class Solution(object):
        def findComplement(self, num):
            """
            :type num: int
            :rtype: int
            """
            v = num
            v |= v >> 1
            v |= v >> 2
            v |= v >> 4
            v |= v >> 8
            v |= v >> 16
            return ~(num | ~v)
    

Log in to reply
 

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