x만큼 간격이 있는 n개의 숫자

NJW·2021년 8월 15일
0

코테

목록 보기
42/170

x와 n을 입력 받아, x의 간격이 있는 숫자 n개를 출력해 준다. 배열을 사용하나 싶었는데, 미리 vector solution이렇게 나와 있었다.

#include <string>
#include <vector>

using namespace std;

vector<long long> solution(int x, int n) {
  vector<long long> answer; //자동으로 할당해주는 컨테이너
  
  for(int i = 1; i <= n; i++){
      answer.push_back(x*i);
  }
  return answer;
}
profile
https://jiwonna52.tistory.com/

0개의 댓글