Missing Number
An array contains n distinct values from 0..n. Return the single missing value using linear time and constant auxiliary space.
Example 1
nums = [3,0,1]2Explanation
Among 0,1,2,3 only 2 is absent.
Example 2
nums = []0Explanation
For n=0 the allowed set is {0}, so the missing value is 0.
Example 3
nums = [0,1]2Explanation
Length two includes value 2 in the allowed range even though it is not an index.
Constraints
- 0 <= n <= 10000
- Values are distinct and within 0..n
Function contract
missingNumberArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 33 cases, on your device.
[3,0,1]