프로그래머스 - JAVA/Level 1
[JAVA] 프로그래머스 Lv.1 : x만큼 간격이 있는 n개의 숫자
새우버거♬
2021. 4. 1. 01:43
예제:
x | n | answer |
2 | 5 | [2, 4, 6, 8, 10] |
4 | 3 | [4, 8, 12] |
-4 | 2 | [-4, -8] |
제한 조건:
- x는 -10000000 이상, 10000000 이하인 정수입니다.
- n은 1000 이하인 자연수입니다.
Solution #1
class Solution {
public long[] solution(long x, int n) {
long[] answer = new long[n];
for (int i = 0; i < n; i++) {
answer[i] = x * (i + 1);
}
return answer;
}
}
Result #1
💡 간단한 문제이지만, 제한 조건에 따라 x 파라미터를 long 타입으로 바꿔줘야 하는 함정(?)이 있다.
More Algorithm!
👇👇
github.com/ggujangi/ggu.programmers
ggujangi/ggu.programmers
프로그래머스 알고리즘, JAVA. Contribute to ggujangi/ggu.programmers development by creating an account on GitHub.
github.com
출처 : 프로그래머스