C# bit mask (if a^b=c then a=b^c)
\npublic class Solution \n{\n    public int FindMaximumXOR(int[] nums) \n    {\n        // All positive so we can start with 30\n        // no more than 31 so w
```\npublic class Solution \n{\n    public int FindMaximumXOR(int[] nums) \n    {\n        // All positive so we can start with 30\n        // no more than 31 so we can use an integer for the mask\n        // if a^b=c then a=b^c\n\n        var mask = 0;\n\n        for (int i = 30; i >= 0; i--)\n        {\n            var contain1Set = new HashSet<int>();\n            var contain0Set = new HashSet<int>();\n            foreach (var number in nums)\n            {\n                if ((number >> i & 1) == 1)\n                {\n                    // i + 1 means the last one.\n                    contain1Set.Add(number >> (i + 1));\n                }\n                else\n                {\n                    contain0Set.Add(number >> (i + 1));\n                }\n            }\n\n            if (contain1Set.Count == 0 || contain0Set.Count == 0) continue;\n\n            // get zero one\n            foreach (var numberWithMask in contain0Set)\n            {\n                var belongTo1Set = ((mask >> (i + 1)) ^ numberWithMask);\n\n                if (contain1Set.Contains(belongTo1Set))\n                {\n                    mask |= (1 << i);\n                    break;\n                }\n            }\n        }\n\n        return mask;\n    }\n}\n```
[]