https://school.programmers.co.kr/learn/courses/30/lessons/42748
Arrays.copyOfRange
int[] arr = {10, 11, 12, 13}; int[] newArr = Arrays.copyOfRange(arr, 0, 3); // {10, 11, 12}
Arrays.copyOfRange(arr, 0, 3);
즉 index가 0~2까지 복사하는 것.
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 newArr[] = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]);
Arrays.sort(newArr);
answer[i] = newArr[commands[i][2]-1];
}
return answer;
}
}