https://school.programmers.co.kr/learn/courses/30/lessons/42748
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 풀이
단순 정렬을 통한 인덱싱 문제여서 쉽지만 스트림을 연습 중이여서 스트림을 통해 더욱 간결한 코드로 구현
코드
import java.util.stream.*;
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
ArrayList<Integer> answer = new ArrayList();
for(int i=0; i<commands.length; i++){
int kNum =IntStream.range(commands[i][0]-1, commands[i][1])
.map(n -> array[n])
.sorted()
.toArray()[commands[i][2]-1];
answer.add(kNum);
}
return answer.stream().mapToInt(Integer::intValue).toArray();
}
}
'Coding Test > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 주식 가격 - 자바 (0) | 2023.08.10 |
---|---|
[프로그래머스] 프로세스 - 자바 (0) | 2023.08.10 |
[프로그래머스] 가장 큰 수 - 자바 (0) | 2023.08.09 |
[프로그래머스] 베스트앨범 - 자바 (0) | 2023.08.09 |
[프로그래머스] 의상 - 자바 (0) | 2023.08.09 |