Given a sorted array nums of distinct integers. The numbers are supposed to form a consecutive sequence starting from some unknown integer start:
start, start+1, start+2, ..., start+n-1
where
n = len(nums)
.
nums
.
Return the missing number if one exists; otherwise return null (or -1, but be consistent).
Requirements
Examples
nums = [4,5,6,8,9]
→ missing is
7
nums = [-3,-2,-1,0,1]
→ no missing → return
null
nums = [10,11,12,13,15]
→ missing is
14
Notes
start
can be any integer (including negative).
nums
is already sorted ascending and contains no duplicates.