728x90

https://school.programmers.co.kr/learn/courses/30/lessons/120924

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제) 등차수열 혹은 등비수열 common이 매개변수로 주어질 때, 마지막 원소 다음으로 올 숫자를 return 하도록 solution 함수를 완성해보세요.

 

 

 

 

 

풀이)

class Solution {
    public int solution(int[] common) {
        int answer = 0;
        
        for(int i=0; i< common.length; i++){
            if(common[2]==common[0]+2*(common[1]-common[0])){
                answer = common[0]+(common.length)*(common[1]-common[0]);
            }else{
                answer = common[0]*(int)Math.pow(common[1]/common[0], common.length);
            }
        }
        
        return answer;
    }
}
728x90