본문 바로가기
PS/programmers

[Programmers/Java] K번째 수

by clolee 2025. 3. 18.

K번째 수

 

문제링크:

https://school.programmers.co.kr/learn/courses/30/lessons/42748

 

코드

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 = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]);
            Arrays.sort(temp);
                
            answer[i] = temp[commands[i][2]-1];
        }
        return answer;
    }
}

댓글