- Background knowledge:
a ^ b = c,
c ^ a = b.
- How to be
greedy? Start from the most significant bit, set it to 1 as the
mask & numand add them all to a
- How to get the mask?
maxthen flip all 0s to 1s, and calculate the length of it.
map.has(n & mask ^ mask), it means there is another num that can do
a ^ b = mask.
- If not, it means the digit should be
- Continue it until mask’s length === max.length.
- Visulize the process: As the process going, less and less nums would be left on both sides.
Given an integer array
nums, return the maximum result of
nums[i] XOR nums[j], where
0 <= i <= j < n.
Input: nums = [3,10,5,25,2,8]