421. Maximum XOR of Two Numbers in an Array

class Solution(object):
    def findMaximumXOR(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        max,mask=0,0
        
        for i in range(31,-1,-1): 
            mask|=(1<
class Solution(object):
    def findMaximumXOR(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        answer=0
        for i in range(31,-1,-1):
            answer<<=1
            prefixes={num>>i for num in nums}
            answer+=any(answer^1^prefix in prefixes for prefix in prefixes)
        return answer
                 
             
            

你可能感兴趣的:(421. Maximum XOR of Two Numbers in an Array)