쌓고 쌓다

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

알고리즘/프로그래머스

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

승민아 2022. 7. 8. 00:50

https://school.programmers.co.kr/learn/courses/30/lessons/12954?language=cpp 

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

전체 코드

#include <string>
#include <vector>

using namespace std;

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

res가 int형인데 통과가 되네요...

x는 1000만, n은 1000일때 오버플로우가 날텐데 이상합니다..

Comments