Python 3 | Standard Trie | Explanations
Explanation\n- Build a trie first\n- For each number num in nums, try to find number which can generate maximum value with num using XOR\n\t- From left to right
### Explanation\n- Build a trie first\n- For each number `num` in `nums`, try to find number which can generate maximum value with `num` using `XOR`\n\t- From left to right, take the reverse bit if possble, otherwise take the same bit, e.g.\n\t- say if the k th bit from left for `num` is `1`, then to make it maximum, we want to take a number whose k th bit is `0` (if possible); if not possible, we take same bit.\n- Check comments for more detail\n### Implementation\n```\nclass TrieNode:\n    def __init__(self):\n        self.children = dict()                        # children nodes\n        self.val = 0                                  # end value \n\nclass Trie:\n    def __init__(self, n):\n        self.root = TrieNode()                        # root node\n        self.n = n                                    # max length of all numbers\n        \n    def add_num(self, num):\n        node = self.root \n        for shift in range(self.n, -1, -1):           # only shift self.n bits \n            val = 1 if num & (1 << shift) else 0      # verify bit from left to right \n            if val not in node.children:\n                node.children[val] = TrieNode()\n            node = node.children[val]\n        node.val = num\n        \nclass Solution:\n    def findMaximumXOR(self, nums: List[int]) -> int:\n        max_len = len(bin(max(nums))) - 2             # get max length of all numbers\' binary\n        trie = Trie(max_len)\n        for num in nums: trie.add_num(num)            # build trie\n            \n        ans = 0\n        for num in nums:                              # for each num, find the number which can create max value with num using XOR\n            node = trie.root \n            for shift in range(max_len, -1, -1):\n                val = 1 if num & (1 << shift) else 0  # verify bit from left to right\n                node = node.children[1-val] if 1-val in node.children else node.children[val] # try opposite bit first, otherwise use same bit\n            ans = max(ans, num ^ node.val)            # maintain maximum\n        return ans    \n```
['Trie', 'Python', 'Python3']