Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def findMaximumXOR(self, nums: List[int]) -> int:
- root={}
- def add(word):
- cur=root
- for i in range(31,-1,-1):
- t=1 if (1<<i) & word else 0
- if t in cur:
- cur=cur[t]
- else:
- cur[t]={}
- cur=cur[t]
- for word in nums:
- add(word)
- ans=0
- for num in nums:
- cur=root
- curans=0
- for i in range(31,-1,-1):
- dig=1 if num & (1<<i) else 0
- if 1-dig in cur:
- cur=cur[1-dig]
- curans=curans |(1<<i)
- else:
- cur=cur[dig]
- ans=max(ans,curans)
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement