/ PRACTICE

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

programmers 바로가기

문제

함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다.

입출력 예

x n answer
2 5 [2,4,6,8,10]
4 3 [4,8,12]
-4 2 [-4, -8]

풀이

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