20 line Java, 2ms (sort + two pointer)
Based on \nInvariant 1: If every 1 bit in a is also 1 in b (a & ~b = 0), then a ^ b = b - a\nInvariant 2: For a given number x in nums, pick y in nums that maxi
Based on \nInvariant 1: If every 1 bit in a is also 1 in b (a & ~b = 0), then a ^ b = b - a\nInvariant 2: For a given number x in nums, pick y in nums that maximize x ^ y, y must be next to x ^ o.\n  (can be proved with proof by contradition)\n```\nclass Solution {\n    public int findMaximumXOR(int[] nums) {\n        Arrays.sort(nums);\n        int o = 0;\n        for (int n : nums) {\n            o |= n;\n        }\n        int max = 0;\n        int i = 0, j = nums.length - 1;\n        while (i < j) {\n            max = Math.max(max, nums[i] ^ nums[j]);\n            if (o - nums[i] > nums[j]) { // Equivalent to: nums[i] ^ o > nums[j]\n                i++;\n            } else {\n                j--;\n            }\n        }\n        return max;\n    }\n}\n```
[]