Skip to content

Commit 18dfd8b

Browse files
committed
leetcode_1539
1 parent aa9bef2 commit 18dfd8b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

1539_Kth_Missing_Positive_Number.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int findKthPositive(vector<int>& arr, int k) {
4+
int misCount=0, ix=0;
5+
for(int i=1; i<arr[arr.size()-1]; i++){
6+
if(arr[ix]==i)
7+
ix++;
8+
else misCount++;
9+
10+
if(misCount==k)
11+
return i;
12+
}
13+
return arr.back()+ (k-misCount);
14+
}
15+
};

0 commit comments

Comments
 (0)