We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3449c17 commit 7eba27bCopy full SHA for 7eba27b
Easy/Kth Missing Positive Integer.java renamed to Easy/Kth Missing Positive Number.java
@@ -1,21 +1,19 @@
1
class Solution {
2
public int findKthPositive(int[] arr, int k) {
3
- int missCount = 0;
4
for (int i = 0; i < arr.length; i++) {
5
- int curr = arr[i];
+ int curr = arr[i] - 1;
6
int prev = i == 0 ? 0 : arr[i - 1];
7
- while (prev < (curr - 1)) {
8
- missCount++;
+ while (prev < curr) {
+ k--;
9
prev++;
10
- if (missCount == k) {
+ if (k == 0) {
11
return prev;
12
}
13
14
15
int curr = arr[arr.length - 1];
16
- while (missCount < k) {
+ while (k-- > 0) {
17
curr++;
18
19
20
return curr;
21
0 commit comments