본문 바로가기

Algorithms

Programers - 2 _ x만큼 간격이 있는 n개의 숫자

 

내 풀이:

using System.Collections.Generic;

public class Solution 
{
    public long[] solution(int x, int n)
            {
                List<long> tempList = new List<long>();

                for (long i = 1; i <= n; i++)
                {
                    tempList.Add(x * i);
                }
                return tempList.ToArray();
            }
}

다른 풀이:

public class Solution 
{
    public long[] solution(int x, int n) {
        long[] answer = new long[n];
        for (int i = 0; i < n; i++)
        {
            answer[i] = (long)x * (i + 1);
        }
        return answer;
    }
}

'Algorithms' 카테고리의 다른 글

Programers - 6 _ 콜라츠 추측  (0) 2022.05.02
Programers - 5 _ 평균 구하기  (0) 2022.05.02
Programers - 4 _ 하샤드 수  (0) 2022.05.02
Programers - 3 _ 핸드폰 번호 가리기  (0) 2022.04.26
Programers - 1 _ 직사각형 별 찍기  (0) 2022.04.20