티스토리 뷰


title: "x만큼 간격이 있는 n개의 숫자"
category: 프로그래머스[Level-1]
tags: [C++, JavaScript, 프로그래머스]
date: "2021-01-21"


문제 링크

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

C++

#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;
}

JavaScript

function solution(x, n) {
  var answer = [];

  for (let i = 1; i <= n; i++) {
    answer.push(x * i);
  }

  return answer;
}
728x90
반응형
댓글
05-21 15:56
링크