์ตœ๋Œ€ 1 ๋ถ„ ์†Œ์š”

ํˆฌ ํฌ์ธํ„ฐ?

ํˆฌ ํฌ์ธํ„ฐ ๋Š” 2๊ฐœ์˜ ํฌ์ธํ„ฐ๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ตœ์ ํ™” ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋งค์šฐ ๊ฐ„๋‹จํ•˜๋‹ค!

ํˆฌ ํฌ์ธํ„ฐ ์ด๋™ ์›์น™?

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ์ด๋ผ๋Š” ๋ฐฐ์—ด์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž.

์—ฌ๊ธฐ์„œ start_index ์™€ end_index ๋ฅผ ์ง€์ •ํ•ด์•ผํ•œ๋‹ค!

๋ณดํ†ต start_index ~ end_index ์‚ฌ์ด์˜ ํ•ฉ ํ˜น์€ ๋‘ ๊ฐ’์˜ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์€๋ฐ, ์ด๋ฅผ sum ์ด๋ผ๊ณ  ํ•˜์ž.

  1. sum > n
    1. sum -= start_index
    2. start_index += 1
  2. sum < n
    1. end_index += 1
    2. sum += end_index
  3. sum == n
    1. end_index += 1
    2. sum += end_index
    3. count += 1

์œ„์™€ ๊ฐ™์€ ์›์น™์„ ๊ฐ–๊ณ  ํฌ์ธํ„ฐ๋ฅผ ์ด๋™์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค!

์‰ฝ๊ฒŒ ์ƒ๊ฐํ•ด๋ณด๋ฉด ๋‘ ๊ฐœ์˜ ํฌ์ธํ„ฐ๊ฐ€ ์กด์žฌํ•˜๊ณ , ํ•˜๋‚˜์˜ ํฌ์ธํ„ฐ(end_index)๊ฐ€ ๋จผ์ € ์ฆ๊ฐ€ํ•˜๋ฉด์„œ ๊ฐ’์„ ์ธก์ •ํ•˜๋‹ค๊ฐ€ ๋ฌธ์ œ์˜ ์š”๊ตฌ์— ์ถฉ์กฑํ•˜๋ฉด count๋ฅผ 1 ์ฆ๊ฐ€ํ•œ ํ›„์— start_index๋ฅผ ๋Œ์–ด์˜ค๋Š” ๋ฐฉ์‹์ด๋‹ค.

๊ด€๋ จ ๋ฌธ์ œ

๋ฐฑ์ค€[2018] - ์ˆ˜๋“ค์˜ ํ•ฉ

๋ฐฑ์ค€[1940] - ์ฃผ๋ชฝ

๋ฐฑ์ค€[1253] - ์ข‹์€ ์ˆ˜

  • [1253] ์ข‹์€ ์ˆ˜ ๋ฌธ์ œ๋Š” ๋‹ค์‹œ ํ’€์–ด๋ณด์ž..

ํƒœ๊ทธ:

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

์—…๋ฐ์ดํŠธ:

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