https://school.programmers.co.kr/learn/courses/30/lessons/42748
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
[JAVA]
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
ArrayList<Integer> answerList = new ArrayList<>();
for(int i = 0; i < commands.length; i++){
//SUB 배열을 담을 List
ArrayList<Integer> subList = new ArrayList<>();
//짜르려는 배열을 담는다.
for(int j = commands[i][0] - 1; j < commands[i][1]; j++){
subList.add(array[j]);
}
//정렬한다.
Collections.sort(subList);
//구하고자하는 인덱스의 값을 answerList에 담는다.
answerList.add(subList.get(commands[i][2] - 1));
}
//List를 Array로 변형 후 반환.
return answerList.stream().mapToInt(Integer::intValue).toArray();
}
}
'algorithm > 프로그래머스' 카테고리의 다른 글
프로그래머스_피로도(JAVA) (0) | 2022.11.18 |
---|---|
프로그래머스_H-Index(JAVA) (0) | 2022.11.17 |
프로그래머스_디스크 컨트롤러(JAVA) (0) | 2022.11.17 |
프로그래머스_다리를 지나는 트럭(JAVA) (0) | 2022.11.16 |
프로그래머스_프린터(JAVA) (0) | 2022.11.14 |