Leetcode 1539. 第 k 个缺失的正整数(DAY 175)---- 二分算法学习期
作者:互联网
文章目录
原题题目
代码实现(首刷自解)
class Solution {
public:
int findKthPositive(vector<int>& arr, int k) {
int pos = 0,pre = 0;
while(pos < arr.size())
{
int disappear_num = arr[pos] - pos - 1;
if(disappear_num >= k)
return pos + k;
pre = arr[pos++];
}
return arr.size()+k;
}
};
标签:pre,arr,原题,int,pos,----,num,175,Leetcode 来源: https://blog.csdn.net/qq_37500516/article/details/120487041