알고리즘/프로그래머스
[JAVA] 프로그래머스 Lv1. k번째수 -다른풀이
수진보배
2020. 10. 13. 17:25
728x90
* 배열복사 *
Arrays.copyOf(원본배열, 복사할 길이)
Arrays.copyOfRange(원본배열, 시작인덱스, 끝인덱스)
import java.util.Arrays;
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 = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]);
Arrays.sort(tmp);
answer[i] = tmp[commands[i][2]-1];
}
return answer;
}
}
728x90