[Algorithm - Programmers] K번째수

nunu·2023년 12월 17일
0

Algorithm

목록 보기
110/142

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

제출 코드

import java.util.*;
class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int length = commands.length;
        int[] answer = new int[length];
        for (int i = 0; i < length; i++) {
            int tl = commands[i][1] - commands[i][0] + 1;
            int[] temp = new int[tl];
            for (int j = 0;  j < tl; j++) {
                temp[j] = array[commands[i][0] + j - 1];
            }
            Arrays.sort(temp);
            answer[i] = temp[commands[i][2] - 1];
        }
        return answer;
    }
}
profile
Hello, I'm nunu

0개의 댓글