함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다. 다음 제한 조건을 보고, 조건을 만족하는 함수, solution을 완성해주세요.
class Solution {
public long[] solution(long x, int n) {
long[] answer = new long[n];
long number =0;
for(int i=0,j=1;i<n;i++,j++){
number = x*j;
answer[i] = answer[i] + number;
}
return answer;
}
}
class Solution {
public long[] solution(int x, int n) {
long[] answer = new long[n];
for(int i = 0; i < n; i++){
answer[i] = (long)x*(i+1);
}
return answer;
}
}
위의 코드와 내 코드를 비교해보면 아래와 같이 고민한 1번과 2번이 해결된다.
1. x 변수를 for 문내에서 형 변환을 진행한다.
2. i의 값을 i+1을 해주고 곱셈을 진행하면 number 변수 선언이 필요가 없다,,,난 멀었따,,,,
오늘도 1 멍청 스탯,,,,