# Java O(nlogn) solution greedy

• From the most significant bit to the least significant bit, try to find two numbers with different bit value in that position. During this process, divide numbers into two groups, and do it recursively. Since we care about the bit value from most significant to least significant position, this is an intuitive greedy solution.

``````public class Solution {
public int findMaximumXOR(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
List<Integer> list = new ArrayList<>();
for (int num : nums) {
}
List<Integer> one = new ArrayList<>();
List<Integer> zero = new ArrayList<>();
if (one.size() > 0 && zero.size() > 0) {
}
}
return 0;
}

private int findMaximumXOR(List<Integer> one, List<Integer> zero, int mask) {
return 0;
}
List<Integer> oneone = new ArrayList<>();
List<Integer> onezero = new ArrayList<>();
List<Integer> zeroone = new ArrayList<>();
List<Integer> zerozero = new ArrayList<>();
int ret = 0;
boolean goodcase = false;
if (oneone.size() > 0 && zerozero.size() > 0) {
goodcase = true;
}
if (onezero.size() > 0 && zeroone.size() > 0) {
goodcase = true;
}
if (!goodcase) {
if (oneone.size() > 0) {
ret = findMaximumXOR(oneone, zeroone, mask >> 1);
} else {
ret = findMaximumXOR(onezero, zerozero, mask >> 1);
}
}
return ret;
}

private void divide(List<Integer> nums, int mask, List<Integer> one, List<Integer> zero) {
for (int num : nums) {
if ((num & mask) != 0) {