Given an array containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Pattern focus: XOR Trick. XOR all indices and values to cancel matched pairs and isolate the missing value.
nums = array of distinct integers from 0 to n with one number missing
the missing number
Example 1:
Input:
nums = [3,0,1]
Output:
2
Explanation:
The numbers 0, 1, and 3 are present, so 2 is missing.
Example 2:
Input:
nums = [0,1]
Output:
2
Explanation:
For n = 2, the missing number is 2.