dsa · easy
Missing Number
nums contains n distinct numbers chosen from 0, 1, …, n. Return the one number in that range that is **missing**.
Arguments
nums— n distinct values from 0..n with one number of that range absent
Example
[3,0,1] → 2.
[0,1] → 2.
[9,6,4,2,3,5,7,0,1] → 8.
Constraints
n == nums.length 1 <= n <= 4*10^4 0 <= nums[i] <= n All the numbers of nums are unique Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [3,0,1] Expected: 2
Example 2
Input: [0,1] Expected: 2
Example 3
Input: [9,6,4,2,3,5,7,0,1] Expected: 8