[C++] clean and easy to understand code. Standard Trie data structure.
\nclass Trie {\npublic:\n    Trie() \n    {\n        next[0] = next[1] = nullptr;\n    }\n    \n\t// destructor has a huge impact to run time.\n    ~Trie()\n   
```\nclass Trie {\npublic:\n    Trie() \n    {\n        next[0] = next[1] = nullptr;\n    }\n    \n\t// destructor has a huge impact to run time.\n    ~Trie()\n    {\n        if (next[0]) {\n            delete next[0];\n        }\n        \n        if (next[1]) {\n            delete next[1];\n        }\n    }\n    \n    void insert(int n) {\n        Trie* cur = this;\n        \n        for (int i = 31; i >= 0; --i) {\n            if (n & (1 << i)) {\n                if (!cur->next[1]) {\n                    cur->next[1] = new Trie();\n                }\n                cur = cur->next[1];\n            } else {\n                if (!cur->next[0]) {\n                    cur->next[0] = new Trie();\n                }\n                cur = cur->next[0];\n            }\n        }\n        \n        cur->val = n;\n    }\n    \n    int findOpposite(int n) {\n        Trie* cur = this;\n        \n        for (int i = 31; i >= 0; --i) {\n            if (n & (1 << i)) {\n                if (cur->next[0]) {\n                    cur = cur->next[0];\n                } else {\n                    cur = cur->next[1];\n                }\n            } else {\n                if (cur->next[1]) {\n                    cur = cur->next[1];\n                } else {\n                    cur = cur->next[0];\n                }\n            }\n        }\n        \n        return cur->val;\n    }\nprivate:\n    int val;\n    Trie* next[2];\n};\n\nclass Solution {\npublic:\n    int findMaximumXOR(vector<int>& nums) {\n        int ans = 0;\n        \n        Trie root;\n        \n        for (auto n : nums) {\n            root.insert(n);\n        }\n        \n        for (auto n : nums) {\n            ans = max(ans, n ^ root.findOpposite(n));\n        }\n        \n        return ans;\n    }\n};\n```
[]