슈콩

[프로그래머스] Lv.1 K번째수 본문

Algorithms/Programmers

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

shukong 2025. 10. 8. 15:17

 

[문제]

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

[소스 코드]

import java.util.*;
class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int n = commands.length;
        int[] answer = new int[n];
        for(int i=0;i<n;i++){
            List<Integer> list = new ArrayList<>();
            int start = commands[i][0] - 1;
            int end = commands[i][1] - 1;
            for(int j=start;j<=end;j++){
                list.add(array[j]);
            }
            Collections.sort(list);
            answer[i] = list.get(commands[i][2]-1);
        }
        return answer;
    }
}