본문 바로가기

코딩테스트(프로그래머스)/LEVEL 1

[프로그래머스/Java] K번째수 - 사좋배 공유 -

*문제

 

*답 (JAVA)

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++) {
			ArrayList temp = new ArrayList();
			for(int j=commands[i][0]-1;j<commands[i][1];j++) {
				temp.add(array[j]);
			}
			temp.sort(Comparator.naturalOrder());
			answer[i]=temp.get(commands[i][2]-1);
			
		}
        return answer;
    }
}