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

김아무개·2023년 4월 29일
0

프로그래머스

목록 보기
36/41

내 코드

class Solution {
    public int[] solution(int[] num_list) {
        int idxLast = num_list.length;
        int[] answer = new int[idxLast + 1];
        System.arraycopy(num_list, 0, answer, 0, idxLast);
        
        answer[idxLast] = answer[idxLast - 1] > answer[idxLast - 2]
                        ? answer[idxLast - 1] - answer[idxLast - 2] 
                        : answer[idxLast - 1] * 2;
        return answer;
    }
}
profile
Hello velog! 

0개의 댓글