https://programmers.co.kr/learn/courses/30/lessons/42748
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
int idx = 0;
for (int[] command : commands) {
int i = command[0], j = command[1], k = command[2];
int[] temp = array.clone();
Arrays.sort(temp, i - 1, j);
answer[idx++] = temp[i + k - 2];
}
return answer;
}
}
commands
를 순회돌며 i
, j
, k
를 가져오고 array
를 복사해 Arrays.sort()
함수를 이용해 부분 배열 정렬후 원하는 위치의 값을 answer
에 넣는다.