알고리즘 공부[Lv.1 K번째 수] (프로그래머스)

박건영(Parkgunyoung)·2022년 8월 25일
0

알고리즘

목록 보기
4/5



import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Solution {
    public List<Integer> solution(int[] array, int[][] commands) {
        int[] answer = new int[commands.length];

        List<Integer> result = new ArrayList<>();
        for (int i = 0; i< commands.length; i++){
            List<Integer> split = new ArrayList<>();
            for (int j =commands[i][0]; j<=commands[i][1];j++){
                split.add(array[j-1]);
            }
            Collections.sort(split);
            result.add(split.get(commands[i][2]-1));
        }

        return result;
    }
}
profile
쓰러지면어때일어나면그만인걸

0개의 댓글