어렵진 않다.
곱으로 풀려다가 합으로 구현한 이유는 합이 곱보다 연산 속도가 빠르기 때문이다.
#include <string>
#include <vector>
using namespace std;
vector<long long> solution(int x, int n) {
vector<long long> answer;
for (int i = 0, temp = x; i < n; i++, temp += x)
answer.push_back(temp);
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 문자열 압축 (0) | 2022.04.28 |
|---|---|
| [프로그래머스] (C++) LV1 직사각형 별찍기 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 행렬의 덧셈 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 핸드폰 번호 가리기 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 하샤드 수 (0) | 2022.04.27 |