C++::프로그래머스 < x만큼 간격이 있는 n개의 숫자 >

jahlee·2023년 7월 25일
0

프로그래머스_Lv.1

목록 보기
48/75
post-thumbnail

주어진 숫자 x부터 같은 간격으로 n개를 담아 리턴해주면 되는 문제이다. 간단한 문제이다.

#include <string>
#include <vector>

using namespace std;

vector<long long> solution(int x, int n) {
    vector<long long> answer;
    answer.push_back(x);
    for (int i=0; i<n-1; i++) {
        answer.push_back(answer.back() + x);
    }
    return answer;
}

0개의 댓글