Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
Example 1
Input: nums = [3,0,1]
Output: 2
Explanation: There are 3 numbers, so the range is 0 to 3. The values 0, 1 and 3 are present, so 2 is missing.
Example 2
Input: nums = [0,1]
Output: 2
Explanation: There are 2 numbers, so the range is 0 to 2. 0 and 1 are present, so 2 is missing.
Example 3
Input: nums = [9,6,4,2,3,5,7,0,1]
Output: 8
Explanation: There are 9 numbers, so the range is 0 to 9. Every value except 8 appears.
The numbers 0..n have a known total (n*(n+1)/2). Subtract the actual sum of nums from that total and the difference is exactly the missing number.
Run checks all cases above. Submit evaluates all test cases.