421 Maximum XOR of Two Numbers in an Array
1. Question
Input: [3, 10, 5, 25, 2, 8]
Output: 28
Explanation: The maximum result is 5 ^ 25 = 28.2. Implementation
class Solution {
public int findMaximumXOR(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int max = 0;
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
max = Math.max(max, nums[i] ^ nums[j]);
}
}
return max;
}
}3. Time & Space Complexity
Last updated