[JavaScript] leetCode : Reverse Words in a String
๐Ÿ““ Algorithm/LeetCode 2022. 5. 16. 20:25

๋ฌธ์ œ Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separa..

ํ•œ ์ฃผ ํšŒ๊ณ : 5์›” ๋‘˜์งธ์ฃผ
๐Ÿ“˜ Retrospect/๐Ÿ’ญ ํšŒ๊ณ  2022. 5. 16. 20:17

5์›” 9์ผ ~ 5์›” 15์ผ ํ•œ ์ฃผ ํšŒ๊ณ  ๊ฒฝํ—˜ํ•œ ๊ฒƒ HTML / Sass node.js๋กœ Sass(dart Sass) ํ™˜๊ฒฝ ์„ธํŒ…ํ•˜๊ธฐ package.json ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€ํ•˜๊ธฐ Sass-lint ์„ค์ •ํ•˜๊ธฐ ์•„์ด์ฝ˜ ํฐํŠธ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ JS ํด๋ž˜์Šค์˜ ์ ‘๊ทผ ์ œ์–ด์ž๋“ค Number, Math, String ๋“ฑ์˜ ๋‹ค์–‘ํ•œ ๊ฐ์ฒด๋“ค git admend๋ฅผ ์‹œ๋„ํ•˜๋‹ค ๊ผฌ์˜€์„ ๋•Œ์˜ ํ•ด๊ฒฐ revert ์‚ฌ์šฉํ•ด๋ณด๊ธฐ leetCode ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด ๋Š๋‚€ ์  git push ์ „์—๋Š” ํ•ญ์ƒ pull ํ•˜๊ณ  reset์€ ํ•จ๋ถ€๋กœ ์‚ฌ์šฉ๋ง์ž. ๋ฌด์—‡์ด๋“  ์‹œ์ž‘ํ•  ๋•Œ ์ฒ˜์Œ์— ๋กœ์ง์„ ๋จผ์ € ์ƒ๊ฐํ•ด๋ณด์ž! ๋ณด์™„ํ•  ์  ๋ธ”๋กœ๊ทธ ๊ธ€ ๋‚ด์šฉ ๋ณด์™„ leetCode ์—์„œ ํ‘ผ ๋‚ด์šฉ๋“ค ์—…๋กœ๋“œ git ๋ช…๋ น์–ด ๊ณต๋ถ€

[JavaScript] leetCode : Implement strStr()
๐Ÿ““ Algorithm/LeetCode 2022. 5. 12. 22:53

๋ฌธ์ œ Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. ๋‘๊ฐœ์˜ ๋ฌธ์ž์—ด needle, haystack์ด ์ฃผ์–ด์งˆ ๋•Œ, haystack์—์„œ needle์˜ ์ฒซ๋ฒˆ์งธ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , needle์ด haystack์˜ ํ•œ ๋ถ€๋ถ„์ด ์•„๋‹ˆ๋ผ๋ฉด -1์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ํ’€์ด const strStr = function(haystack, needle) { if (needle.length === 0) return 0; let index = -1; if (haystack.includes(needle)) { let firstLette..

[JavaScript] leetCode : Longest Common Prefix
๐Ÿ““ Algorithm/LeetCode 2022. 5. 9. 23:16

๋ฌธ์ œ Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". ํ•œ ๋‹จ์–ด๊ฐ€ ์š”์†Œ์ธ ๋ฐฐ์—ด์ด ์ฃผ์–ด์งˆ ๋•Œ, ์š”์†Œ์˜ ๋ฌธ์ž์—ด์—์„œ ์กด์žฌํ•˜๋Š” ๊ฐ€์žฅ ๊ธด ์ ‘๋‘์‚ฌ๋ฅผ ์ฐพ์•„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์—†๋‹ค๋ฉด ๋นˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜. ํ’€์ด const longestCommonPrefix = (strs) => { if (strs.length === 0) return ''; if (strs.length === 1) return strs[0]; let prefix = ''; let prev = ''; for (let i = 0; i < strs[0].lengt..

ํ•œ ์ฃผ ํšŒ๊ณ  : 5์›” ์ฒซ์งธ์ฃผ
๐Ÿ“˜ Retrospect/๐Ÿ’ญ ํšŒ๊ณ  2022. 5. 8. 21:40

5์›” 2์ผ ~ 5์›” 8์ผ ํ•œ ์ฃผ ํšŒ๊ณ  ์ฐจ์งˆ์ด ์ƒ๊ฒจ ๋ชฉํ‘œํ•˜๋Š” ๋ถ€๋ถ„์„ ์ข€ ๋ฐ”๊พธ์–ด์„œ ๊ณ„ํš์„ ์ƒˆ๋กญ๊ฒŒ ์งฐ๋‹ค. ํ•™์Šตํ•œ ๊ฒƒ HTML ์›น์ ‘๊ทผ์„ฑ ์ค‘ ์Šคํฌ๋ฆฐ ๋ฆฌ๋”์—์„œ ๊ณ ๋ คํ•ด์•ผ ํ•  ์š”์†Œ๋“ค. JS DOM ๋‹ค๋ฃจ๊ธฐ ๋ฐฐ์—ด์˜ ๋‚ด์žฅ ๋ฉ”์„œ๋“œ๋“ค ์•Œ๊ณ ๋ฆฌ์ฆ˜ / ์ž๋ฃŒ๊ตฌ์กฐ ์Šคํƒ์˜ ๊ตฌ์กฐ ํ† ๋ผ์™€ ๊ฑฐ๋ถ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋Š๋‚€ ์  ์œ ๋ฐ๋ฏธ ๊ฐ•์˜๋กœ๋„ ์ถฉ๋ถ„ํžˆ ํ•ด๋ณผ๋งŒ ํ•˜๊ฒ ๋‹ค.. HTML ๋ ˆ์ด์•„์›ƒ ์งœ๊ธฐ ์ „์— ๊ณ ๋ฏผ์„ ์ถฉ๋ถ„ํžˆ ํ•ด์•ผํ•œ๋‹ค. ๋ณด์™„ํ•  ์  ๊ฐ์ฒด๋ฅผ ๋ฐฐ์—ด๋กœ, ๋ฐฐ์—ด์„ ๊ฐ์ฒด๋กœ ๋‹ค๋ฃจ๋Š” ๋ถ€๋ถ„ ์—ฐ์Šต. ๋ฐฐ์—ด ๋ฉ”์„œ๋“œ๋“ค์ด ๋” ์ต์ˆ™ํ•ด์งˆ ์ˆ˜ ์žˆ๋„๋ก ๋งŽ์ด ๋‹ค๋ค„๋ณด๊ธฐ ๋ธ”๋กœ๊ทธ ๊ธ€ ๋‚ด์šฉ๋“ค์„ ๋” ๋ณด์™„ํ•ด์•ผ๊ฒ ๋‹ค. (์ˆ˜์ •ํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ํ•œ ๋ถ€๋ถ„๋“ค + ๊นŠ์ด)

[JavaScript] leetCode : Linked List Cycle II
๐Ÿ““ Algorithm/LeetCode 2022. 5. 3. 23:56

๋ฌธ์ œ Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle. Note tha..

[JavaScript] leetCode : Valid Mountain Array
๐Ÿ““ Algorithm/LeetCode 2022. 5. 2. 21:57

๋ฌธ์ œ Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if arr.length >= 3 There exists some i with 0 arr[i + 1] > ... > arr[arr.length - 1] ๋ฐฐ์—ด์ด ์‚ฐ์ฒ˜๋Ÿผ ์˜ค๋ฆ„์ฐจ์ˆœ-๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๋Š”์ง€ ํ™•์ธํ•˜์—ฌ boolean์œผ๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฌธ์ œ. ์กฐ๊ฑด์€ ๋ฐฐ์—ด์˜ ๊ธธ์ด๊ฐ€ 3 ์ด์ƒ์ด์–ด์•ผ ํ•˜๊ณ , ์˜ค๋ฆ„์ฐจ์ˆœ๊ณผ ๋‚ด๋ฆผ์ฐจ์ˆœ์˜ ..

ํ•œ ์ฃผ ํšŒ๊ณ  : 4์›” ๋„ท์งธ์ฃผ
๐Ÿ“˜ Retrospect/๐Ÿ’ญ ํšŒ๊ณ  2022. 5. 1. 19:46

4์›” 25์ผ ~ 5์›” 1์ผ ํ•œ ์ฃผ ํšŒ๊ณ  ํ•™์Šตํ•œ ๊ฒƒ JS ํ”„๋กœ๋ฏธ์Šค์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค. ์ด๋ฒคํŠธ ์ „ํŒŒ์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค. Canvas API๋ฅผ ์ ‘ํ–ˆ๋‹ค. ์ž๋ฃŒ๊ตฌ์กฐ/์•Œ๊ณ ๋ฆฌ์ฆ˜ ์Šคํ„ฐ๋””๋ฅผ ํ†ตํ•ด leetCode๋ฅผ ํ•˜๋ฃจ์— 4๋ฌธ์ œ์”ฉ ํ’€์–ด๋ณด๊ณ  ์žˆ๋‹ค. ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ์˜ ๋‹ค์–‘ํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ์ ‘ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„์— ๋Œ€ํ•ด ์ •๋ฆฌํ–ˆ๋‹ค. ๋Š๋‚€์  ์Šคํ„ฐ๋””๋ฅผ ํ†ตํ•ด ๊ณต๋ถ€์‹œ๊ฐ„์„ ๋งŽ์ด ๋Š˜๋ฆฌ๊ณ  ์žˆ๋‹ค. ์‰ฝ์ง€ ์•Š์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜! ๋‹ค์–‘ํ•œ ๋ฌธ์ œ๋“ค์„ ์ ‘ํ•ด๋ณด๊ณ  ์žˆ๋‹ค. 1์ผ 1ํฌ์ŠคํŒ…์„ ๋˜๋„๋ก ์˜๋ฏธ์žˆ๊ฒŒ ํ•ด๋ณด๋ ค ํ•˜๊ณ ์žˆ๋Š”๋ฐ ์‰ฝ์ง€ ์•Š๋‹ค. ๋ณด์™„ํ•  ์  ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ค€๋น„ํ•˜๊ธฐ ์ด๊ฒƒ์ €๊ฒƒ ํ•ด๋ณด๋ฉฐ DOM ์กฐ์ž‘์„ ๋งŽ์ด ํ•ด๋ณด๊ธฐ 1์ผ 1ํฌ์ŠคํŒ… ๋‚ด์šฉ ๋ณด์™„ํ•˜๊ธฐ

์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„๋ณต์žก๋„์™€ Big-O
๐Ÿ““ Algorithm 2022. 4. 29. 22:22

๋“ค์–ด๊ฐ€๋ฉฐ ๊ธฐ์™•์ด๋ฉด ๊ฐ€์žฅ ๋น ๋ฅธ ๊ธธ๋กœ ๊ฐ€์ž! ์ถœํ‡ด๊ทผ์„ ํ•˜๊ฑฐ๋‚˜, ์นœ๊ตฌ์™€์˜ ์•ฝ์† ๋“ฑ๋“ฑ. ์–ด๋”˜๊ฐ€๋ฅผ ํ–ฅํ•  ๋•Œ ์šฐ๋ฆฌ๋Š” ํ•ญ์ƒ ๋ชฉ์ ์ง€๋กœ ๊ฐ€๋Š” ๋น ๋ฅธ ๋ฃจํŠธ๋ฅผ ์ฐพ์•„๋ณด๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋‹ค. ์ปดํ“จํ„ฐ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋‹ค. ํ”„๋กœ๊ทธ๋žจ์„ ์‹œํ–‰ํ•  ๋•Œ ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ ๊ฐ€์žฅ ๋‚ฎ์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์„ ํƒํ•˜์—ฌ ํšจ์œจ์ ์œผ๋กœ ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•˜๋ ค ํ•œ๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์–ด๋–ค ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ๊ณผ์ •(๋ช…๋ น์–ด)๋“ค์˜ ๋‹จ๊ณ„์ ์ธ ๋‚˜์—ด์„ ๋งํ•œ๋‹ค. ์–ด๋–ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๋” ํšจ์œจ์ ์ธ๊ฐ€๋ฅผ ํ‰๊ฐ€ํ•˜๋Š” ๋ฐ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์ง€ํ‘œ๋“ค์ด ์‚ฌ์šฉ๋œ๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ‰๊ฐ€ ์ง€ํ‘œ ์ •ํ™•์„ฑ ์ž‘์—…๋Ÿ‰ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰ ์ตœ์ ์„ฑ ํšจ์œจ์„ฑ ์‹œ๊ฐ„ ๋ณต์žก๋„ => ์ˆ˜ํ–‰ํ–ˆ์„ ๋•Œ ์–ผ๋งŒํผ์˜ ์‹œ๊ฐ„์ด ์†Œ์š”๋˜๋Š”์ง€? ๊ณต๊ฐ„ ๋ณต์žก๋„ => ์–ผ๋งŒํผ์˜ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์‚ฌ์šฉ๋˜๋Š”์ง€? ๋ณดํ†ต ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ์ค‘์š”ํ•˜๊ฒŒ ์—ฌ๊ฒจ์ง€๋Š” ๋ถ€๋ถ„์€ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰๊ณผ ํšจ์œจ์„ฑ, ๊ทธ ์ค‘์—์„œ๋„ ์‹œ๊ฐ„ ๋ณต์žก๋„์ด๋‹ค..

[JavaScript] ์ด๋ฒคํŠธ ์ „ํŒŒ bubbling, capturing
๐Ÿ“” Studying/JavaScript 2022. 4. 28. 23:36

์ด๋ฒคํŠธ ๊ฐ์ฒด ์šฐ๋ฆฌ๊ฐ€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๋™์ ์ธ ๊ธฐ๋Šฅ์„ ์œ„ํ•ด ์ด๋ฒคํŠธ๋ฅผ ๋“ฑ๋กํ•˜๊ณ ์ž ํ•  ๋•Œ๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ์ง€๋งŒ, ํ”ํžˆ๋“ค addEventListener()๊ณผ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณค ํ•œ๋‹ค. ๋ธŒ๋ผ์šฐ์ €๋Š” ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๊ฒฐ๊ณผ์ ์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์€ ์ด๋ฒคํŠธ ๊ฐ์ฒด event object๋ฅผ ๋งŒ๋“ ๋‹ค. ๋ธŒ๋ผ์šฐ์ €๋Š” ์ด๋ฒคํŠธ๋ฅผ ์–ด๋–ป๊ฒŒ ๊ฐ์ง€ํ•ด์„œ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด ๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ผ๊นŒ? ์ด๋Ÿฐ ๊ถ๊ธˆ์ฆ์„ ํ•ด๊ฒฐํ•ด์ฃผ๋Š” ์ด๋ฒคํŠธ๋ฅผ ๊ฐ์ง€ ํ•˜๋Š” ํŠน์„ฑ์ด ์žˆ๋‹ค. ๋ฐ”๋กœ ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง๊ณผ ์ด๋ฒคํŠธ ์บก์ณ๋ง, ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์ด๋‹ค. ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง Event Bubbling ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง์€ ๋น„๋ˆ„๋ฐฉ์šธ์ด ์•„๋ž˜์—์„œ ์˜ฌ๋ผ์˜ค๋Š” ๊ฒƒ๊ณผ ๋น„์Šทํ•˜๊ฒŒ ์ƒ๊ฐํ•˜๋ฉด ์ข€ ๋” ์ˆ˜์›”ํ•œ ์ดํ•ด๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ํ•ด๋‹น ์ด๋ฒคํŠธ๊ฐ€ ๋” ์ƒ์œ„์˜ ์š”์†Œ๋“ค๋กœ ์ „๋‹ฌ๋˜๋Š” ํŠน์„ฑ์„ ๋งํ•œ๋‹ค. Article๋ถ€ํ„ฐ Butt..