Algorithm
[ํ๋ก๊ทธ๋๋จธ์ค] [Level 1] x๋งํผ ๊ฐ๊ฒฉ์ด ์๋ n๊ฐ์ ์ซ์
seulye
2022. 5. 12. 12:09
๋ฌธ์ ์ค๋ช
ํจ์ solution์ ์ ์ x์ ์์ฐ์ n์ ์ ๋ ฅ ๋ฐ์, x๋ถํฐ ์์ํด x์ฉ ์ฆ๊ฐํ๋ ์ซ์๋ฅผ n๊ฐ ์ง๋๋ ๋ฆฌ์คํธ๋ฅผ ๋ฆฌํดํด์ผ ํฉ๋๋ค. ๋ค์ ์ ํ ์กฐ๊ฑด์ ๋ณด๊ณ , ์กฐ๊ฑด์ ๋ง์กฑํ๋ ํจ์, solution์ ์์ฑํด์ฃผ์ธ์.
์ ํ ์กฐ๊ฑด
- x๋ -10000000 ์ด์, 10000000 ์ดํ์ธ ์ ์์ ๋๋ค.
- n์ 1000 ์ดํ์ธ ์์ฐ์์ ๋๋ค.
์ ์ถ๋ ฅ ์
xnanswer2 | 5 | [2,4,6,8,10] |
4 | 3 | [4,8,12] |
-4 | 2 | [-4, -8] |
ํ์ด
import java.util.*;
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;
}
}โ