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 start = commands[i][0]-1;
int end = commands[i][1]-1;
int k = commands[i][2]-1;
int[] temp = Arrays.copyOfRange(array, start, end+1);
Arrays.sort(temp);
answer[i] = temp[k];
}
return answer;
}
}
array.clone() : 배열 복사
int[] arr = {1,2,3};
int[] copyArr = arr.clone(); // copyArr = {1,2,3}
Arrays.copyOfRange() : 배열을 시작~끝-1 만큼 복사
int[] arr = {1,2,3,4,5};
int[] copyArr = Arrays.copyOfRange(arr, 1, 3); // copyArr = {2,3}
'1d-1c > Programmers' 카테고리의 다른 글
Level1_예산 (JAVA) (0) | 2020.11.02 |
---|---|
Level1_두 개 뽑아서 더하기 (JAVA) (0) | 2020.10.31 |
Level1_크레인 인형뽑기 게임 (JAVA) (0) | 2020.10.31 |
Level1_완주하지 못한 선수 (C++) (JAVA) (0) | 2020.10.31 |
도둑질 (C++) (0) | 2020.04.25 |