Make Unreal REAL.
article thumbnail
Level 0. 다음에 올 숫자

 

 

#include <iostream>
#include <vector>

using namespace std;

int solution(vector<int> common)
{
    int diff = common[1] - common[0];

    return (diff == common[2] - common[1]) ? common.back() + diff : common.back() * (common[1] / common[0]);
}

 

특별한 것은 없었던 문제다.

 

첫 번째, 두 번째, 세 번째 원소를 확인해 등차수열인지 확인하고 마지막 원소에 등차를 더하거나 등비를 곱해 해결한다.

'자료구조 & 알고리즘 > 프로그래머스' 카테고리의 다른 글

Level 0. 평행  (1) 2023.01.24
Level 0. 최빈값 구하기  (0) 2023.01.23
Level 0. 연속된 수의 합  (0) 2023.01.21
Level 0. 종이 자르기  (0) 2023.01.20
Level 0. 캐릭터의 좌표  (0) 2023.01.19
profile

Make Unreal REAL.

@diesuki4

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그