My solution:

class Solution {
    public int missingElement(int[] nums, int k) {
        int i=1;
        for(;i<nums.length;i++){
             int diff = nums[i]-nums[i-1]-1;
            if(diff>=k){
                return nums[i-1]+k;
            }else{
                k-=diff;
            }
   
        }
        return nums[nums.length-1]+k;
            
    }
}

 

posted on 2022-04-14 11:43  阳光明媚的菲越  阅读(17)  评论(0编辑  收藏  举报