Publish:

ํƒœ๊ทธ: , , , , ,

์นดํ…Œ๊ณ ๋ฆฌ:

img_3.png

๋ฌธ์ œ

๋ฌธ์ œ ๋งํฌ

img_3.png

ํ’€์ด

์ฒซ๋ฒˆ์งธ ํ’€์ด (์˜ค๋ฒ„ํ”Œ๋กœ์šฐ)

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 ๋ฌธ ๋ฐ–์—์„œ ํ•˜๋ฉด ๋œ๋‹ค.

๋ฐฉ๋ฌธํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋Œ“๊ธ€,์ง€์ ,ํ”ผ๋“œ๋ฐฑ ์–ธ์ œ๋‚˜ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜Š

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ