[프로그래머스]마지막 두 원소

박예림·2023년 5월 25일
0

코테

목록 보기
98/132

import java.util.stream.IntStream;
class Solution {
    public int[] solution(int[] num_list) {
        int[] answer = new int[num_list.length+1];

        int end = num_list[num_list.length-1];
        int endBack = num_list[num_list.length-2];

        IntStream.range(0, num_list.length).forEach(i -> answer[i] = num_list[i]);

        answer[answer.length-1] = end > endBack ? (end-endBack) : end*2;
        return answer;
    }
}
profile
응애 나 아기개발자

0개의 댓글