LeetCode 1539. Kth Missing Positive Number
2021-01-27 20:37:04
# leetcode
Problem
LeetCode 1539. Kth Missing Positive Number
1. 题目简述
给出一个有序数组和一个正整数k,找到第k个缺失的正整数。例如:
Example:
Input: arr = [2,3,4,7,11], k = 5
Output: 9
Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9.
2. 算法思路
二分查找最重要的是确认好check函数,到底是求上边界还是下边界。搞清楚!!!而且具体题目具体分析。
这道题里,需要注意的点是check函数中,这里的判断条件是小于还是小于等于。
1 | class Solution { |