-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode1539.java
More file actions
29 lines (28 loc) · 787 Bytes
/
leetcode1539.java
File metadata and controls
29 lines (28 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
public class leetcode1539 {
public static int findKthPositive(int[] arr, int k) {
List<Integer> ls=new ArrayList<>();
int temp=arr[0];
if(arr[0]==1 && arr[arr.length-1]==arr.length){
return arr[arr.length-1]+k;
}
for(int i=0;i<arr.length;i++){
if(temp==arr[i]){
temp++;
}
else{
for(int j=arr[i-1];j<arr[i];j++){
ls.add(j);
}
temp=arr[i];
}
}
return ls.get(k);
}
@SuppressWarnings("unused")
public static void main(String args[]){
int arr[]={1,2,3,4};
int k=2;
System.out.println(findKthPositive(arr, k));
}
}