17. Find the Missing Number
MediumMath~12 min
An array contains n distinct numbers taken from the range 0 to n, which means exactly one number in that range is missing.
Return the missing number.
Examples
Example 1
- Input:
- nums = [3, 0, 1]
- Output:
- 2
- Why:
- n = 3, so the range is 0..3 and 2 is absent.
Example 2
- Input:
- nums = [0, 1]
- Output:
- 2
Constraints
1 <= nums.length <= 10000All numbers are distinct and within 0..n.