Problem
nums holds n distinct numbers taken from the range 0 to n, so exactly one number in that range is missing. Return it. Try for O(n) time and O(1) extra space.
Example 1
- Input
- nums = [3, 0, 1]
- Output
- 2
Example 2
- Input
- nums = [0, 1]
- Output
- 2
- Why
- n = 2, so the range is 0..2
Example 3
- Input
- nums = [9, 6, 4, 2, 3, 5, 7, 0, 1]
- Output
- 8
Constraints
n == nums.length1 <= n <= 10^40 <= nums[i] <= nAll the numbers of nums are unique.