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();
}
}
반응형
'프로그래머스_C# > Level_1' 카테고리의 다른 글
[프로그래머스 C#] 평균 구하기 (0) | 2021.06.27 |
---|---|
[프로그래머스 C#] 하샤드 수 (0) | 2021.06.18 |
[프로그래머스 C#] 핸드폰 번호 가리기 (0) | 2021.06.04 |
[프로그래머스 C#] 행렬의 덧셈 (0) | 2021.05.23 |
[프로그래머스 C#] 직사각형 별찍기 (0) | 2021.05.16 |