C++ || Trie data structure || Easy approach
Here is my c++ code for this problem.\n\'\'\'\n\n\tclass Node{\n\n\t\tpublic:\n\t\tNode links[2];\n\t};\n\tclass Trie{\n\n\t\tpublic:\n\t\tNode root;\n\t\tTrie(
Here is my c++ code for this problem.\n\'\'\'\n\n\tclass Node{\n\n\t\tpublic:\n\t\tNode* links[2];\n\t};\n\tclass Trie{\n\n\t\tpublic:\n\t\tNode* root;\n\t\tTrie(){\n\t\t\troot=new Node();\n\t\t}\n\t\tvoid insert(int num){\n\t\t\tNode* node=root;\n\t\t\tfor(int i=31; i>=0; i--){\n\t\t\t\tint bit=(num>>i)&1;\n\t\t\t\tif(!node->links[bit]){\n\t\t\t\t\tnode->links[bit]=new Node();\n\t\t\t\t}\n\t\t\t\tnode=node->links[bit];\n\t\t\t}\n\t\t}\n\t\tint maxnum(int num){\n\t\t\tNode* node=root;\n\t\t\tint maxi=0;\n\t\t\tfor(int i=31; i>=0; i--){\n\t\t\t\tint bit=(num>>i)&1;\n\t\t\t\tif(!node->links[1-bit]){\n\t\t\t\t\tnode=node->links[bit];\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tmaxi=maxi|(1<<i);\n\t\t\t\t\tnode=node->links[1-bit];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn maxi;\n\t\t}\n\t};\n\n\tclass Solution {\n\n\t\tpublic:\n\t\tint findMaximumXOR(vector<int>& nums) {\n\t\t\tint ans=0;\n\t\t\tTrie trie;\n\t\t\tfor(int i=0; i<nums.size(); i++){\n\t\t\t\ttrie.insert(nums[i]);\n\t\t\t}\n\t\t\tfor(int i=0; i<nums.size(); i++){\n\t\t\t\tans=max(ans, trie.maxnum(nums[i]));\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t};\n\'\'\'
['Trie', 'C']