Programmers/Level1
x만큼 간격이 있는 n개의 숫자
zzunsik
2021. 7. 7. 16:33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import java.util.*;
class Solution {
public long[] solution(int x, int n) {
long[] answer = {};
long res = x;
List<Long> list = new ArrayList<Long>();
for (int i = 0; i < n; i++) {
list.add(res);
res += x;
}
answer = list.stream().mapToLong(Long::longValue).toArray();
return answer;
}
}
|
cs |
long list to long array로 변환하였다.
좀 어렵게 푼 감이 있는데, 더 단순하게 n만큼 long 배열을 할당하고 for문을 돌려도 된다.