C++ O(n) trie beat 85%
\nclass Solution {\npublic:\n    struct node{\n        // val at the leaf is value of path from root to leaf\n        int val;\n        // two links, 0 and 1, f
```\nclass Solution {\npublic:\n    struct node{\n        // val at the leaf is value of path from root to leaf\n        int val;\n        // two links, 0 and 1, for each bit\n        struct node* link[2];\n        node(){\n            val=0;\n            link[0]=link[1]=NULL;\n        }\n    };\n    struct node* start=new node();\n    \n    void insertTrie(int x){\n    \t// straightforward insertion from msb to lsb\n        struct node* ptr=start;\n        for(int i=31;i>=0;i--){\n            bool curbit=(x&(1<<i));\n            if(ptr->link[curbit]==NULL)\n                ptr->link[curbit]=new node();\n            ptr=ptr->link[curbit];\n        }\n        ptr->val=x;\n    }\n    \n    int checkTrie(int x){\n    \t// checking from msb to lsb(least significat bit)\n        struct node* ptr=start;\n        for(int i=31;i>=0;i--){\n            bool curbit=(x&(1<<i));\n            // if curbit is 1,see if we can have a number with that bit 0 to maximize the xor\n            if(ptr->link[1-curbit]!=NULL)\n                ptr=ptr->link[1-curbit];\n            // if not then proceed with curbit\n            else if(ptr->link[curbit]!=NULL)\n                ptr=ptr->link[curbit];\n        }\n        return ptr->val;    \n    }\n    int findMaximumXOR(vector<int>& nums) {\n        int ans=0,n=nums.size();\n        if(nums.size()<2) return 0;\n        insertTrie(nums[0]);\n        for(int i=1;i<n;i++){\n        \t// for nums[i], we are finding element in nums[0 to i-1] with which it\'s xor will be max\n            ans=max(ans,nums[i]^checkTrie(nums[i]));\n            // add nums[i] to the trie\n            insertTrie(nums[i]);\n        }\n        return ans;\n    }\n};\n```
['Trie', 'C']