- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberOfK.java
More file actions
Latest commit
27 lines (25 loc) · 895 Bytes
/
Copy pathNumberOfK.java
File metadata and controls
27 lines (25 loc) · 895 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
packagedev.solar.level1;
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.List;
publicclassNumberOfK {
publicint[] solution(int[] array, int[][] commands) {
//TODO
int[] answer = newint[commands.length];
for (inti = 0; i < commands.length; i++) {
List<Integer> tempList = newArrayList<>();
for (intj: commands[i]) {
tempList.add(j);
}
int[] copyArray = Arrays.copyOf(array, array.length);
int[] ints = Arrays.copyOfRange(copyArray, tempList.get(0)-1, tempList.get(1));
Arrays.sort(ints);
// System.out.println(tempList.get(2)-1);
answer[i] = ints[tempList.get(2)-1];
// for (int z = 0; z < ints.length; z++) {
// System.out.println(ints[z]);
// }
}
returnanswer;
}
}