프로그래머스 1단계 - x만큼 간격이 있는 n개의 숫자

Genie·2021년 11월 18일
0

프로그래머스

목록 보기
1/2

🔍 문제 설명

https://programmers.co.kr/learn/courses/30/lessons/12954

💡 Trouble Shooting

int * int 를 했을 때 int 범위를 초과할 경우 overflow 가 일어난다.
따라서 long 으로 변환해주는게 중요하다.

📝 소스코드

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;
    }
}
profile
차근차근

0개의 댓글