Skip to content

Commit 7eba27b

Browse files
authored
Update and rename Kth Missing Positive Integer.java to Kth Missing Positive Number.java
1 parent 3449c17 commit 7eba27b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Easy/Kth Missing Positive Integer.java renamed to Easy/Kth Missing Positive Number.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
class Solution {
22
public int findKthPositive(int[] arr, int k) {
3-
int missCount = 0;
43
for (int i = 0; i < arr.length; i++) {
5-
int curr = arr[i];
4+
int curr = arr[i] - 1;
65
int prev = i == 0 ? 0 : arr[i - 1];
7-
while (prev < (curr - 1)) {
8-
missCount++;
6+
while (prev < curr) {
7+
k--;
98
prev++;
10-
if (missCount == k) {
9+
if (k == 0) {
1110
return prev;
1211
}
1312
}
1413
}
1514
int curr = arr[arr.length - 1];
16-
while (missCount < k) {
15+
while (k-- > 0) {
1716
curr++;
18-
missCount++;
1917
}
2018
return curr;
2119
}

0 commit comments

Comments
 (0)