1/**2* @param {number[]} arr3* @param {number} k4* @return {number}5*/6varfindKthPositive =function(arr, k) {7let start = 0;8let end = arr.length - 1;9while(start <=end) {10let mid = start + Math.floor((end - start) / 2);11let missing = arr[mid] - mid - 1;1...
CodeTestcase Test Result Test Result 1539. Kth Missing Positive Number Easy Topics Companies Hint Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Return the kth positive integer that is missing from this array. Example 1: Input: arr = [2...
1539. Kth Missing Positive Number 解题方法 设置start = missingcount = 0,遍历arr,记录到此数字为止一共有多少个缺失的数字missingcount,然后设置start = arr[i],设置当前位置为开始位置,这时如果missingcount >= k的话,说明需要选的数已经包含在遗漏的数里面了,break。循环结束根据missingcount和k的大小关系,如...
【leetcode】1539. Kth Missing Positive Number 题目如下: Given an arrayarrof positive integers sorted in a strictly increasing order, and an integerk. Find thekthpositive integer that is missing from this array. Example 1: Input: arr = [2,3,4,7,11], k = 5 Output: 9 Explanation: The ...
LC 1539. Kth Missing Positive Number (二分) link 随着i增加,缺失的个数非减,在i处缺失的个数为arr[i]-(i+1).二分找到第一个缺失个数大于等于k的位置left, 则left-1处缺失的个数<k。left-1处缺失的个数为arr[left-1]-left, 还差k-arr[left-1]+left个,则答案是k+left....
1539. Kth Missing Positive Number packageLeetCode_1539/*** 1539. Kth Missing Positive Number *https://leetcode.com/problems/kth-missing-positive-number/* Given an array arr of positive integers sorted in a strictly increasing order, and an integer k....
https://leetcode.com/problems/kth-missing-positive-number/solutions/779999/java-c-python-o-logn/ My two cents on thought process for binary search: Here we have three sorted sequences: let n be len(A), then 1st sorted sequence is array values: ...
1539. Kth Missing Positive Number (E) Kth Missing Positive Number (E) 题目 Given an arrayarrof positive integers sorted in astrictly increasing order, and an integerk. Find thekthpositive integer that is missing from this array. Example 1:...