프로그래머스 코딩테스트/JAVA
[프로그래머스] K번째수 JAVA
Coding-Su
2024. 8. 2. 00:08
728x90
제목
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
정답
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
ArrayList<Integer> nums = new ArrayList<>();
for (int arr : array) {
nums.add(arr);
}
for (int i = 0; i < commands.length; i++) {
List<Integer> sub = nums.subList(commands[i][0]-1, commands[i][1]);
List<Integer> subNum = new ArrayList<>(sub);
Collections.sort(subNum);
answer[i] = subNum.get(commands[i][2]-1);
}
return answer;
}
}728x90