import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = {};
List<Integer> tempList;
List<Integer> answerList = new ArrayList<>();
for (int i = 0; i < commands.length; i++) {
tempList = new ArrayList<>();
for (int k = commands[i][0]-1; k<commands[i][1]; k++) {
tempList.add(array[k]);
}
Collections.sort(tempList);
answerList.add(tempList.get(commands[i][2]-1));
}
answer = new int[answerList.size()];
for(int i=0;i<answerList.size();i++){
answer[i]=answerList.get(i);
}
return answer;
}
}
'문제풀이' 카테고리의 다른 글
프로그래머스 소수 찾기 JAVA (feat. 에라토스테네스의 체) (0) | 2021.03.25 |
---|---|
프로그래머스 모의고사 Java (0) | 2021.03.24 |
Leetcode Coin Change Java (0) | 2021.01.20 |
Leetcode Count and Say Java (0) | 2021.01.20 |
Leetcode MinStack JAVA (0) | 2021.01.05 |