Maximum XOR of Two Numbers in an Array
Very simple trie code please upvote\n\n\nstruct Node{\n  Node*links[2];\n  bool isContains(int bit){\n    return (links[bit] != NULL);\n  }\n  void put(int bit 
**Very simple trie code please upvote**\n```\n\nstruct Node{\n  Node*links[2];\n  bool isContains(int bit){\n    return (links[bit] != NULL);\n  }\n  void put(int bit , Node* node){\n    links[bit] = node;\n  }\n  \n  Node* get(int bit)\n  {\n    return links[bit];\n  }\n};\n\nclass Trie{\n  \n  private:\n  \n   Node* root;\n  \n  public:\n  Trie(){\n    root = new Node();\n  }\n  \n  void insert(int num)\n  {\n    Node* node = root;\n    int maxnum =0 ;\n    for(int i = 31 ; i>=0 ; i-- ){\n       int bit = (num >> i) & 1;\n       if(!node->isContains(bit)){\n         node->put(bit , new Node());\n       }\n      node = node->get(bit);\n    }\n  }\n  \n  public:\n  \n  int getMax(int num){\n    Node* node = root;\n    int maxnum =0;\n    for(int i = 31 ;i >=0; i--){\n      int bit = (num >> i) & 1;\n\t  // search for all opposite bit they will give maximun xor (1^0) == 1 or (0^1) ==1\n\t  // if we not find opposite bit continue with the original bit\n      if(node->isContains(!bit)){\n        maxnum = maxnum | (1<<i);\n        node = node->get(!bit);\n      }else{\n        node = node->get(bit);\n      }\n    }\n    return maxnum;\n  }\n};\n\nclass Solution {\npublic:\n    int findMaximumXOR(vector<int>& nums) {\n        Trie node;\n        for(auto it : nums) node.insert(it);\n        int maxi = 0;\n      // loop over all the elements find max\n       for(auto it : nums){\n         maxi = max(maxi , node.getMax(it));\n       }\n      return maxi;\n      return 0;\n    }\n};\n```
[]