You are given an array nums containing n distinct numbers taken from the range 0 through n.
Exactly one value in that range is missing. Return the missing number.
Input / output
nums: int[][0, n]Examples
nums = [3, 0, 1] returns 2.nums = [0, 1] returns 2.nums = [9,6,4,2,3,5,7,0,1] returns 8.Constraints
1 <= nums.length <= 1000000 <= nums[i] <= nums.lengthnums are distinct.Edge cases
0.n itself.Target complexity
O(n) time and O(1) extra space.Hints
0 + 1 + ... + n with the actual array sum.Follow-up What other constant-space approach can you derive using XOR instead of arithmetic sums?