본문 바로가기

코딩 테스트/프로그래머스

[Level 1, C++] x만큼 간격이 있는 n개의 숫자

728x90
반응형

#include <string>
#include <vector>
#include <iostream>
using namespace std;

vector<long long> solution(int x, int n) {
    vector<long long> answer;
    long long temp = x;
    if(x == 0) {
        for(long long i=0; i<n; i++){
            answer.push_back(0);
        }
        
        return answer;
    }
    else{
        for(long long i=temp; i!=temp*n + temp; i+=temp) {
            answer.push_back(i);
        }
    }
    
    return answer;
}
728x90
반응형