---
# System prepended metadata

title: 1060. Missing Element in Sorted Array
tags: [Leetcode, FaceBook, Binary Search, Medium]

---

# 1060. Missing Element in Sorted Array
###### tags: `Leetcode` `FaceBook` `Medium` `Binary Search`
Link: https://leetcode.com/problems/missing-element-in-sorted-array/
## 思路
binary search
注意边界条件是用nums[mid]-nums[0]-mid不是nums[mid]-nums[0]
## Code
```java=
class Solution {
    public int missingElement(int[] nums, int k) {
        int start = 0;
        int end = nums.length;
        while(start<end){
            int mid = start+(end-start)/2;
            if(k > nums[mid]-nums[0]-mid){
                start = mid+1;
            }
            else{
                end = mid;
            }
        }
        start-=1;
        return nums[start]+k-(nums[start]-nums[0]-start);
    }
}
```