FE๋ฅผ ํ–ฅํ•ดโ†—โ†—

ํ’€์ด๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(nums) { const numsSetSize = new Set(nums).size; const numsHalfCount = nums.length / 2; return numsSetSize > numsHalfCount ? numsHalfCount : numsSetSize; } /* (ํ’€์ด) ์ฃผ์–ด์ง„ ๋ฐฐ์—ด์„ Set ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•ด์ฃผ๊ณ  numsSetSize๊ฐ€ nums์˜ ๊ฐœ์ˆ˜ / 2 ๋ณด๋‹ค ๋งŽ์œผ๋ฉด nums.length์˜ ์ ˆ๋ฐ˜์ธ numsHalfCount๋ฅผ ๋ฆฌํ„ดํ•ด์ฃผ๊ณ  ์•„๋‹ˆ๋ฉด numsSetSize๋ฅผ ๋ฆฌํ„ดํ•ด์ค€๋‹ค. ์†”์งํžˆ ๋˜ ํžˆ๋“ ์ผ€์ด์Šค๊ฐ€ ์žˆ๋‹ค๋˜๊ฐ€ ํ•ด์„œ ์‹คํŒจํ•  ์ค„ ์•Œ์•˜๋Š”๋ฐ ํ†ต๊ณผ๋๋‹ค. ํ…Œ์ŠคํŠธ์˜ ์ด๋ฆ„์„ ๋ณด๋‹ˆ ํ•ด์‹œ์ธ๋ฐ ๊ด€๋ จ ์ž๋ฃŒ๋ฅผ ์ฐพ์•„๋ณด๋‹ˆ ํ•ด์‹œ๋Š” ์ž„์˜์˜ ๊ธธ์ด์˜ ๋ฐ์ดํ„ฐ๋ฅผ..
ํ’€์ด ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(sizes) { const maxSizes = Math.max(...sizes.flat()); let secondMaxSizes = 0; for (el of sizes) { if (el[0] > el[1]) { if (el[1] > secondMaxSizes) { secondMaxSizes = el[1]; } } else { if (el[0] > secondMaxSizes) { secondMaxSizes = el[0]; } } } return maxSizes * secondMaxSizes; } ๋ถˆํ•„์š”ํ•œ if ๋ฌธ์ด ๋งŽ์•„๋ณด์ธ๋‹ค.. ํ”ผ๋“œ๋ฐฑ function solution(sizes) { const maxSize = Math.max(...sizes.flat());..
์Šคํƒ (stack) ์Šคํƒ์€ ํ•œ ์ชฝ ๋์—์„œ๋งŒ ์ž๋ฃŒ๋ฅผ ๋„ฃ๊ฑฐ๋‚˜ ๋บ„ ์ˆ˜ ์žˆ๋Š” ์„ ํ˜• ๊ตฌ์กฐ(LIFO - Last In First Out)์ด๋‹ค. ๋งจ ์œ„์ชฝ ์•„์ดํ…œ์„ top์ด๋ผ ํ•œ๋‹ค. ์ž๋ฃŒ๋ฅผ ๋„ฃ๋Š”๊ฒƒ์„ push, ๋„ฃ์–ด๋‘” ์ž๋ฃŒ๋ฅผ ๊บผ๋‚ด๋Š” ๊ฒƒ์„ pop์ด๋ผ ํ•œ๋‹ค. pop์‹œ ๊บผ๋‚ด์ง€๋Š” ์ž๋ฃŒ๋Š” ๊ฐ€์žฅ ์ตœ๊ทผ์— pushํ•œ ์ž๋ฃŒ๋ถ€ํ„ฐ ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค. ๋ณดํ†ต ์Šคํƒ์€ ์œ„๊ฐ€ ๋šซ๋ฆฐ ๋น„์ปค ์ด๋ฏธ์ง€๋ฅผ ์ƒ์ƒํ•˜๋ฉด ํŽธํ•˜๋‹ค. ์Šคํƒ์ด ๊ฝ‰์ฐจ๋ฉด Stack Overflow , ๋น„์–ด์žˆ๋Š” ์ƒํƒœ๋ฅผ Underflow๋ผ ํ•œ๋‹ค.
Learned Array.from์— ๋Œ€ํ•ด ์กฐ๊ธˆ ๋” ์ดํ•ดํ–ˆ๋‹ค. ์žฌ๊ท€ํ•จ์ˆ˜์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค. ์ž๋ฃŒ๊ตฌ์กฐ ์Šคํƒ / ํ์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค. Liked ๊ตฌ๊ธ€๋ง์ด ์•„๋‹Œ ๋‚ด ๋จธ๋ฆฌ๋กœ ํ•œ์ฃผ ๋ฌธ์ œ๋ฅผ ๋‹ค ํ’€์—ˆ๋‹ค. ์Šคํƒ/ํ์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜๋ฉฐ ์ดํ•ด๋„๊ฐ€ ์˜ฌ๋ž๋‹ค. Lacked ๋ณ€์ˆ˜ ํ‚ค์›Œ๋“œ ์‹ค์ˆ˜. ๋ฌธ์ œํ’€์ด์— ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ๊ธธ๋‹ค. ํ• ๊ฒŒ ๋งŽ์•„์„œ ์ •๋ฆฌ๋ฅผ ๋ฏธ๋ฃจ๊ฒŒ ๋œ๋‹ค.
ํ’€์ด ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(s) { const strArr = s.split(" "); let result = ""; for (let i = 0; i < strArr.length; i++) { for (let j = 0; j < strArr[i].length; j++) { result += !(j % 2) ? strArr[i][j].toUpperCase() : strArr[i][j].toLowerCase(); } if (i < strArr.length - 1) { result += " "; } } return result; } /* (ํ’€์ด) ํžˆ๋“ ์ผ€์ด์Šค ํ•ด๊ฒฐ์— ์ •๋ง ๋งŽ์€ ์‹œ๊ฐ„์„ ๋ฒ„๋ ธ๋‹ค.. 2์ค‘ for๋ฌธ์œผ๋กœ split์œผ๋กœ ๋‚˜๋ˆ ์ค€ strArr ๋ฐฐ์—ด์š”์†Œ์˜ ๊ฐœ์ˆ˜๋งŒํผ ๋Œ๋ ค์ฃผ๊ณ  ๋‚ด๋ถ€ for๋ฌธ์—์„œ..
ํ’€์ด ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(arr) { return arr.filter((el, idx) => el !== arr[idx + 1]); } ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์Šคํƒ/ํ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์ด์šฉํ•ด ํ‘ธ๋Š” ํ’€์ด์˜€๋Š”๋ฐ ํ’€์ด์ž์ฒด๋Š” ์ข‹์ง€๋งŒ ๋ฌธ์ œ์˜๋„์— ๋งž์ง€์•Š๋‹ค. ์˜๋„์— ๋งž๋Š” ํ’€์ด์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž. ๋ฌธ์ œ ์˜๋„์— ๋งž๋Š” ํ’€์ด function solution(arr) { const result = []; for (const el of arr) { const lastElement = result[result.length - 1]; if (lastElement !== el) result.push(el); } return result; } ์Šคํ„ฐ๋”” ๋ฆฌ๋”๋‹˜์ด ์˜ฌ๋ ค์ฃผ์‹  ํ’€์ด. ์Šคํƒ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„ ํ’€์ด๋‹ค. ๋‚˜๋Š” ์š”์†Œ๋ฅผ ๋นผ๊ณ  ๋„ฃ๋Š” ์ž‘์—…..
ํ (Queue) FIFO(First In First Out) ์„ ๊ธฐ์ค€์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ์ž๋ฃŒ๊ตฌ์กฐ๋‹ค. ( ๋จผ์ € ๋“ค์–ด์˜จ ๋ฐ์ดํ„ฐ๊ฐ€ ๋จผ์ € ๋‚˜๊ฐ„๋‹ค ) ๋ฐ์ดํ„ฐ์˜ ์‚ฝ์ž…ํ•˜๋Š” ๋ถ€๋ถ„์€ rear ์‚ญ์ œํ•˜๋Š” ๋ถ€๋ถ„์„ fornt ๋ผ ๋ถ€๋ฅธ๋‹ค. ํ์˜ ์ข…๋ฅ˜๋Š” ์„ ํ˜• ํ(Linear Queue), ์›ํ˜• ํ(Circular Queue) ๋“ฑ์ด ์žˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฅผ ์ง‘์–ด๋„ฃ๋Š” enqueue, ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”์ถœํ•˜๋Š” dequeue ๋“ฑ์˜ ์ž‘์—…์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ๋Š” ์ˆœ์„œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š” ์ž‘์—…์„ ์ž„์‹œ๋กœ ์ €์žฅํ•ด๋‘๋Š” ๋ฒ„ํผ(buffer)๋กœ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ push, shift๋กœ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•˜๋‚˜ shift์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” ์ตœ๋Œ€ O(n)์ด๋‹ˆ ์ฃผ์˜ํ•˜์ž. const arr = []; //enqueue arr.push('test1'); arr.push('test2..
ํ’€์ด ๐Ÿ™Ž๐Ÿป‍โ™‚๏ธ function solution(n, m) { return [maxAcommonDivisor(n, m), (n * m) / maxAcommonDivisor(n, m)]; } function maxAcommonDivisor(a, b) { let remainder = 0; while (b !== 0) { remainder = a % b; a = b; b = remainder; } return a; } /* (ํ’€์ด) ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค. ํ•จ์ˆ˜๋Š” ๋‚˜๋จธ์ง€ ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋Š” ๋ณ€์ˆ˜ํ•˜๋‚˜๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๊ณ  while ๋ฌธ์œผ๋กœ b๊ฐ€ 0์ด ๋˜๋ฉด ํƒˆ์ถœํ•˜๊ฒŒ ๋˜๋Š”๋ฐ ์ด์œ ๋Š” (a๊ฐ€ ์ž‘์„๊ฒฝ์šฐ) remainder = a ๊ฐ€ ๊ทธ๋Œ€๋กœ ๋“ค์–ด๊ฐ a = b a๋ณด๋‹ค ํฐ๊ฐ’์ธ b๊ฐ€ ๋“ค์–ด๊ฐ b = remainder ๋‚˜๋จธ์ง€๊ฐ’์ด ..
YunCow
'๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (4 Page)