프로그래머스_C#/Level_1
[프로그래머스 C#] x만큼 간격이 있는 n개의 숫자
최애뎡
2021. 5. 29. 15:07
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/12954
코딩테스트 연습 - x만큼 간격이 있는 n개의 숫자
함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다. 다음 제한 조건을 보고, 조건을 만족하는 함수, solution을 완성해주세요.
programmers.co.kr
using System.Collections.Generic;
public class Solution {
public long[] solution(int x, int n) {
List<long> answer = new List<long>();
long su = x;
for (int i = 0; i < n; i++)
{
answer.Add(su);
su += x;
}
return answer.ToArray();
}
}
반응형