Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
classSolution { public: intmissingElement(vector<int>& nums, int k){ int l = 0, r = nums.size() - 1; while(l < r) { int m = l + (r - l) / 2; int alpha = nums[m] - (m + nums[0]); //how many skips if(alpha < k) { l = m + 1; } else { r = m - 1; } } int diff = nums[l] - (l + nums[0]) - k; if(diff >= 0) return nums[l] - diff - 1; return nums[l] - diff; } };