프로그래머스(다음에 올 숫자)

개발자되고싶은데·2025년 11월 22일

class Solution {
    public int solution(int[] common) {
        int answer = 0;
        if((common[1]-common[0]) == (common[2]-common[1])) {
            int diff = common[1] - common[0];
            int lastIndex = common.length - 1;
            answer = common[lastIndex] + diff;
        }
        else{
            int ref = common[1]/common[0];
            int lastIndex = common.length-1;
            answer= common[lastIndex]*ref;
        }
        return answer;
    }
}

쉽게 해결했다

0개의 댓글