Playground/자바문제집

[프로그래머스] K번째 수

미숫가루설탕많이 2023. 2. 18. 17:54
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++) {
            int[] temp = Arrays.copyOfRange(array, commands[i][0] - 1, commands[i][1]);
            Arrays.sort(temp);
            
            answer[i] = temp[commands[i][2] - 1];
        }
        return answer;
    }
}