class Solution {
public long[] solution(int x, int n) {
long[] answer = new long[n];
answer[0] = x;
for(int idx = 1; idx < n; idx++){
answer[idx] = answer[idx - 1] + x;
}
return answer;
}
}
import java.util.stream.LongStream;
class Solution {
public long[] solution(int x, int n) {
return LongStream.iterate(x, i->i+x).limit(n).toArray();
}
}
: LongStream.iterate(x, i -> i + x) : x부터 시작하여 i를 i + x로 계속 증가하는 LongStream을 생성
: limit(n) : 스트림에서 반환할 개수를 제한 -> 입력으로 주어진 n만큼의 요소만을 선택해 반환
: toArray() : 스트림의 요소들을 배열로 변환