문제 풀이 : 2021.05.10
command 별로 임의의 배열을 만들어서 sort함수 적용
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for(int i = 0;i<commands.length;i++){
int[] tmp = new int[commands[i][1]-commands[i][0]+1];
int k = 0;
for(int j = commands[i][0]-1;j<commands[i][1];j++){
tmp[k] = array[j];
k++;
}
Arrays.sort(tmp);
answer[i] = tmp[commands[i][2]-1];
}
return answer;
}
}
문제 출처 링크