공부노트/Programmers
[Java, 자바]Programmers - K번째수
drexqq
2020. 6. 22. 16:46
728x90
반응형
import java.util.Arrays;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = {};
answer = new int[commands.length];
for (int i = 0; i < commands.length; i++) {
int[] temp = new int[commands[i][1]-commands[i][0]+1];
int index = 0;
for (int j = commands[i][0]-1; j < commands[i][1]; j++) {
temp[index] = array[j];
index++;
}
Arrays.sort(temp);
answer[i] = temp[commands[i][2]-1];
}
return answer;
}
}
K번째를 구하는 코드를 Array를 이용하여 작성해보았다.
728x90
반응형