반응형
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
// answer을 commands 길이의 배열로 생성
int[] answer = new int[commands.length];
// commands의 길이만큼 반복
for (int x = 0; x < commands.length; x++) {
// 임시 배열 temp 생성하고 Array 함수를 통해 array의 commands에 입력된
// 숫자를 start와 end 길이로 자름
int[] temp = Arrays.copyOfRange(array, commands[x][0]-1, commands[x][1]);
// Array 메소드로 temp를 오름차순 정렬
Arrays.sort(temp);
// answer[x]에 temp의 commands[x][2]에 있는 숫자 인덱스-1 번째에 위치한 숫자를 입력
answer[x] = temp[commands[x][2]-1];
}
return answer;
}
}
반응형
'Programming > Algorithm' 카테고리의 다른 글
for문 계단 만들기 알고리즘 - 자바 (0) | 2021.07.06 |
---|---|
구구단 출력 알고리즘 - 코틀린 (0) | 2021.04.16 |
동명이인 찾기 알고리즘 - 파이썬 (0) | 2021.04.15 |