Strong Root

난이도 

 

문제를 보시려면 여기를 클릭

 

 

 

힌트

Java 내장 sort를 이용하면 쉽게 풀리는 기초문제

 

 

 

이하는 코드입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
public class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int[] answer = new int[commands.length];
 
        for (int i = 0; i < commands.length; i++) {
            List<Integer> list = new ArrayList<>();
 
            int start = commands[i][0- 1;
            int end = commands[i][1- 1;
            int pick = commands[i][2- 1;
 
            for (int j = start; j <= end; j++) {
                list.add(array[j]);
            }
 
            Collections.sort(list);
            answer[i] = list.get(pick);
        }
 
        return answer;
    }
}
cs