JAVAIARY

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

examplePractice

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

shiherlis 2023. 2. 19. 13:26

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

 

프로그래머스

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

programmers.co.kr

public int solution(int[] common) {
		int answer = 0;
		// 1. 수열의 길이는 항상 3 이상
		// 2. 등차수열인지 확인
			if (common[1]-common[0]==common[2]-common[1]) {
				answer= common[common.length-1]+(common[1]-common[0]);
			}
		// 3. 그렇지 않은 경우 등비수열
			else {
				answer = common[common.length-1]*(common[1]/common[0]);
			}
		return answer;
	}