programmers 20260502

This commit is contained in:
songyc macbook 2026-05-02 19:17:46 +09:00
parent beaad56afc
commit bfa71e91d8
3 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,14 @@
등차수열 혹은 등비수열 common이 매개변수로 주어질 때,
마지막 원소 다음으로 올 숫자를 return 하도록 solution 함수를 완성해보세요.
제한사항
2 < common의 길이 < 1,000
-1,000 < common의 원소 < 2,000
common의 원소는 모두 정수입니다.
등차수열 혹은 등비수열이 아닌 경우는 없습니다.
등비수열인 경우 공비는 0이 아닌 정수입니다.
입출력 예
common result
[1, 2, 3, 4] 5
[2, 4, 8] 16

View File

@ -0,0 +1,10 @@
function solution(common) {
var _a = [common[0], common[1], common[2]], a = _a[0], b = _a[1], c = _a[2];
var len = common.length;
if (a + c === 2 * b)
return common[len - 1] + (b - a);
else
return common[len - 1] * (b / a);
}
var common = [1, 2, 3, 4];
console.log(solution(common));

View File

@ -0,0 +1,10 @@
function solution(common: number[]) {
let [a, b, c]: number[] = [common[0], common[1], common[2]];
let len: number = common.length;
if(a + c === 2 * b) return common[len - 1] + (b - a);
else return common[len - 1] * (b / a);
}
let common: number[] = [1,2,3,4];
console.log(solution(common));