반응형
문제분석:
할게없다 그냥 시키는대로 하면된다. 배열을 자르고, 정렬하고, 뽑으면댄다
1
2
3
4
5
6
7
8
9
10
11
12
|
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[] temp = Arrays.copyOfRange(array, commands[i][0]-1,commands[i][1]);
Arrays.sort(temp);
answer[i]=temp[commands[i][2]-1];
}
return answer;
}
}
|
cs |
문제풀이:
자바 메소드(API)를 어느정도 알고있다면 쉽다.
1.자르기 :Arrays.copyOfRange(array,자를 첫번째위치, 자를 두번째위치) ->잘랐다면 자른배열 반환
2.정렬 : Arrays.sort(temp); ->정렬
3.뽑기
반응형
'알고리즘 > 프로그래머스 Level1' 카테고리의 다른 글
[프로그래머스,Java] Level1: 음양 더하기 (0) | 2021.08.07 |
---|---|
[프로그래머스,java] Level1: 체육복 (2021년 7월 28일 업데이트버전) (3) | 2021.08.06 |
[프로그래머스,Java] Level1 : 위클리 챌린지 1주차 (0) | 2021.08.06 |
[프로그래머스,Java] Level1 : 완주하지 못한 선수 (0) | 2021.08.04 |
[프로그래머스,Java] Level1 : 폰켓몬 (0) | 2021.08.04 |