-Code
class Solution {
public int solution(int[] common) {
int len = common.length - 1;
if (len == 1) return common[1] * 2 - common[0];
int[] gaps = new int[2];
for (int i = 1; i < 3; i++) {
gaps[i - 1] = common[i] - common[i - 1];
}
if (gaps[0] == gaps[1]) {
return common[len] + gaps[0];
}
return common[len] * (gaps[1] / gaps[0]);
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 등수 매기기 (0) | 2025.02.21 |
---|---|
[프로그래머스/Java] 문자열 밀기 (0) | 2025.02.21 |
[프로그래머스/Java] OX퀴즈 (0) | 2025.02.21 |
[프로그래머스/Java] 저주의 숫자 3 (0) | 2025.02.21 |
[프로그래머스/Java] 치킨 쿠폰 (0) | 2025.02.20 |