출처 : https://school.programmers.co.kr/learn/courses/30/lessons/42748
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer =new int [commands.length];
for(int i=0;i<commands.length;i++){
int [] sub =new int[commands[i][1]-commands[i][0]+1];
for(int j=0;j<commands[i][1]-commands[i][0]+1;j++){
sub[j]=array[j+commands[i][0]-1];
}
Arrays.sort(sub);
answer[i]=sub[commands[i][2]-1];
}
return answer;
}
}
배열을 오름차순 정렬하는 Arrays.sort를 안다면 쉽게 풀 수 있을 것 입니다.
'알고리즘 > Lv1. 프로그래머스' 카테고리의 다른 글
푸드 파이트 대회 (0) | 2023.07.11 |
---|---|
두 개 뽑아서 더하기 (0) | 2023.07.11 |
숫자 문자열과 영단어 (0) | 2023.07.11 |
1차 비밀지도 (0) | 2023.07.07 |
추억 점수 (0) | 2023.07.04 |