[PS] 99ํด๋ฝ ์ฝํ ์คํฐ๋ 2์ผ์ฐจ TIL (x๋งํผ ๊ฐ๊ฒฉ์ด ์๋ n ๊ฐ์ ์ซ์)
ํ๊ทธ: 99ํด๋ฝ, PS, TIL, ๋ฐฐ์ด, ์ฝ๋ฉํ ์คํธ์ค๋น, ํญํด99
์นดํ ๊ณ ๋ฆฌ: PS
๋ฌธ์
ํ์ด
์ฒซ๋ฒ์งธ ํ์ด (์ค๋ฒํ๋ก์ฐ)
1
2
3
4
5
6
7
8
9
class Solution {
public long[] solution(int x, int n) {
long[] answer = new long[n];
for (int i = 0, j = x; i < n; i++, j+= x) {
answer[i] = j;
}
return answer;
}
}
์ฒ์ ํ์ด์์ j ๋ฅผ for ๋ฌธ์์ ์ด๊ธฐํ ํ๋ค๋ณด๋ j + x ์ ๊ฒฐ๊ณผ๊ฐ int ๋ฒ์์ธ ์ต๋ 21์ต์ ๋ฒ์ด๋๊ฒ ๋๋ฉด ์ค๋ฒํ๋ก์ฐ๊ฐ ๋ฐ์ํ๋ค. for (int i = 0, long j = x โฆ) ์ด๋ฐ์์ผ๋ก ๊ฐ๋ฅํ ์ค ์์๋๋ฐ ํด๋น ๋ฐฉ๋ฒ์ ๋ฌธ๋ฒ ์ค๋ฅ๋ฅผ ๋ฐ์์ํจ๋ค.
๋๋ฒ์งธ ํ์ด
1
2
3
4
5
6
7
8
9
10
class Solution {
public long[] solution(int x, int n) {
long[] answer = new long[n];
long j = x;
for (int i = 0; i < n; i++, j+= x) {
answer[i] = j;
}
return answer;
}
}
j ์ ์ด๊ธฐํ ๋ถ๋ถ์ for ๋ฌธ ๋ฐ์์ ํ๋ฉด ๋๋ค.
๋๊ธ๋จ๊ธฐ๊ธฐ