문서 색인

2. 코드

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int[] answer = {};

        int commandsLength = commands.length;
        answer = new int[commandsLength];

        for (int c=0; c<commandsLength; c++) {
            int i = commands[c][0];
            int j = commands[c][1];
            int k = commands[c][2];

            System.out.println(i + " " + j + " " + k);

            List<Integer> list = new ArrayList<Integer>();
            for ( int number = i-1; number <= j-1; number++ ) {
                list.add(array[number]);
            }

            Collections.sort(list);

            for ( Integer integer : list ) {
                System.out.println(integer);
            }

            answer[c] = list.get(k-1);
        }
        return answer;
    }
}