go代码
func getMissingNumber(nums []int) int {
if len(nums) == 0 || len(nums) == 1 ||
nums[len(nums) - 1] == len(nums) - 1{
return len(nums)
}
if nums[0] !=0 {
return 0
}
start,end :=0,len(nums)-1
for ;end - start > 1 ; {
mid := (start + end) >> 1
if nums[mid] <= mid {
start = mid
}else {
end = mid
}
}
return nums[end]-1
}