[JS] ์•Œ๊ณ ๋ฆฌ์ฆ˜ : ๋‘ ์ˆ˜์˜ ์ตœ๋Œ€ ํ•ฉ
728x90

๋ฌธ์ œ

์ˆ˜์—ด์ด ์ฃผ์–ด์งˆ ๋•Œ, ์ด์ค‘ ๋‘ ๊ฐœ์˜ ์ˆ˜๋ฅผ ์„ ํƒํ•˜์—ฌ ์ตœ๋Œ€ ํ•ฉ์ด ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ํ”„๋กœ๊ทธ๋žจ์„ ์ œ์ž‘ํ•˜๋ผ. ์ž…๋ ฅ์€ ์ •์ˆ˜๋กœ ๋œ ๋ฐฐ์—ด์„ ๋ฐ›๊ณ , ์ตœ๋Œ€ ํ•ฉ์ด ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š” ๋‘ ์ˆ˜๋ฅผ ๋ฐฐ์—ด ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ฐฐ์—ด๋กœ ์ž…๋ ฅ๋˜๋Š” ์ •์ˆ˜๋Š” 10 ~ 20๊ฐœ ์‚ฌ์ด์ด๋ฉฐ, ์ •์ˆ˜์˜ ๋ฒ”์œ„๋Š” -20 ~ +20 ์‚ฌ์ด์˜ ๊ฐ’์ด ์ž…๋ ฅ๋œ๋‹ค.

 

์ž…๋ ฅ๊ฐ’

[-11, 5, 18, -2, -3, 6, 4, 17, 10, 9]

[3, 7, -14, 2, -6, 13, -20, -2, -7, 6, -17, -5, 14, -9, 19]

[-15, -4, -8, 12, 12, -8, -8, 9, 10, 15, -2, 10, -14, 2, 13, 19, -9, 3, -18, 14]

 

์ถœ๋ ฅ๊ฐ’

#1 [18, 17]

#2 [19, 14]

#3 [19, 15]

 

 

๐Ÿ‘ฉ‍๐Ÿ’ป ํ’€์–ด๋ณด๊ธฐ

function answer(nums) {
  let result = [];

  nums.sort((x, y) => x - y);
  nums.reverse();

  result.push(nums[0]);
  result.push(nums[1]);
  return result;
}

 

์ฒซ ๋ฒˆ์งธ ์ตœ๋Œ€๊ฐ’๊ณผ ๊ทธ ๊ฐ’์„ ์ œ์™ธํ•œ ๋‘ ๋ฒˆ์งธ ์ตœ๋Œ€๊ฐ’์„ ๊ตฌํ•ด์„œ ๋”ํ•˜๋ฉด ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

๋จผ์ € ๋ฐฐ์—ด์„ sort ๋ฉ”์„œ๋“œ๋กœ ์ •๋ ฌํ•œ๋’ค ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ–ˆ๋‹ค.

์ดํ›„ ์ •๋ ฌ๋œ ๋ฐฐ์—ด์—์„œ ๋‘ ๊ฐœ์˜ ๊ฐ’์„ ๊บผ๋‚ด์™”๋‹ค.

 

 

๋ถ€์กฑํ–ˆ๋˜ ์ 

  • ๋งค๊ฐœ๋ณ€์ˆ˜ ์›๋ณธ ํ˜•ํƒœ๋ฅผ ๋ณ€ํ˜•ํ•ด๋„ ๊ดœ์ฐฎ์€๊ฐ€์— ๋Œ€ํ•œ ์˜๋ฌธ...

 

 

 

 


๐Ÿคธ‍โ™€๏ธ๐Ÿคธ‍โ™€๏ธ๐Ÿคธ‍โ™€๏ธ๐Ÿคธ‍โ™€๏ธ๐Ÿคธ‍โ™€๏ธ๐Ÿคธ‍โ™€๏ธ

๋ฐฉ๋ฌธํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ™Œ

ํฌ์ŠคํŒ…๋“ค์€ ๊ณต๋ถ€์ค‘์ธ ๋‚ด์šฉ์„ ๊ธ€๋กœ ์ž‘์„ฑํ•œ ๊ฒƒ์ด๋ผ ๋ถ€์กฑํ•œ ์ ์ด ๋งŽ์œผ๋‹ˆ ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. 

๋ถ€์กฑํ•œ ๋ถ€๋ถ„์— ๋Œ€ํ•œ ์ฝ”๋ฉ˜ํŠธ๋Š” ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค.

์ข‹์€ ํ•˜๋ฃจ ๋˜์„ธ์š”, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ™‚

 

 

728x90