프로그래머스 - K번째수

parkkhee·2023년 4월 14일
0

Level1

목록 보기
19/23
import java.util.*;

class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int[] answer = new int[commands.length];
        int[] num;
        
        
        for(int i=0; i<commands.length; i++){
            List<Integer> arr = new ArrayList<>();
            for(int j=commands[i][0]-1; j<commands[i][1]; j++){
                
                arr.add(array[j]);
                
            }
            Collections.sort(arr);
            
            answer[i] = arr.get(commands[i][2]-1);
            
        }
        
        
        return answer;
    }
}
profile
순우리말 백엔드 개발자

0개의 댓글