[프로그래머스-JAVA] 정렬

유진·2024년 7월 18일
0

코딩테스트

목록 보기
2/18

📝 프로그래머스 - JAVA

K번째수 (Level 1)

import java.util.Arrays;

class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int[] answer = new int[commands.length];
        
        for (int idx = 0; idx < commands.length; idx++) {
            int i = commands[idx][0];
            int j = commands[idx][1];
            int k = commands[idx][2];
            
            int[] subArray = Arrays.copyOfRange(array, i - 1, j);
            Arrays.sort(subArray);
            answer[idx] = subArray[k - 1];
        }
        
        return answer;
    }
}
profile
유진진입니덩

0개의 댓글