Missing Number
Given an array nums containing n distinct numbers drawn from the range [0, n], return the single number in that range that is missing from the array.
Open official problem prompt ↗Identify the one value from 0..n that never shows up in an array of the other n values.
A teacher calls the class roll from a list numbered 0 to n. Every student who answers gets checked off both on the roster and against a seat number; the one seat number that never gets a matching answer is the absent student.
- Input
- nums = [3, 0, 1]
- Output
- 2
- Why
- n = 3, so the full range is [0, 3]; the array holds 0, 1, 3, leaving 2 missing.
n == nums.length1 <= n <= 10^40 <= nums[i] <= nAll the numbers of nums are unique