웅재의 코딩세상

[프로그래머스] x만큼 간격이 있는 n개의 숫자 본문

코딩테스트/프로그래머스 - LV 1

[프로그래머스] x만큼 간격이 있는 n개의 숫자

웅드 2024. 2. 9. 17:08

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

vector<long long> solution(int x, int n) {
    vector<long long> answer(n);
    answer.front() = x;
    for(int i =0; i<n-1; i++){
        answer.at(i+1) = answer.at(i) + x;
    }
    return answer;
}
반응형