From d96cdb86f3477160535da61651debc8eedd7830e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Mon, 25 Aug 2025 14:01:03 +0900 Subject: [PATCH 1/3] valid-parentheses --- valid-parentheses/jun0811.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 valid-parentheses/jun0811.js diff --git a/valid-parentheses/jun0811.js b/valid-parentheses/jun0811.js new file mode 100644 index 0000000000..b0718a732f --- /dev/null +++ b/valid-parentheses/jun0811.js @@ -0,0 +1,22 @@ +/** + * @param {string} s + * @return {boolean} + */ +var isValid = function (s) { + const match = { + ')': '(', + ']': '[', + '}': '{', + }; + if (match[s[0]]) return false; + const stack = []; + for (const bracket of s) { + if (bracket == '(' || bracket == '{' || bracket == '[') stack.push(bracket); + else { + const openBracket = stack.pop(); + if (match[bracket] != openBracket) return false; + } + } + if (stack.length > 0) return false; + return true; +}; From 43123dc8600c5343142a0fca6eec651218a6b0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Mon, 25 Aug 2025 15:11:30 +0900 Subject: [PATCH 2/3] container-with-most-water --- container-with-most-water/jun0811.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 container-with-most-water/jun0811.js diff --git a/container-with-most-water/jun0811.js b/container-with-most-water/jun0811.js new file mode 100644 index 0000000000..96dd484e36 --- /dev/null +++ b/container-with-most-water/jun0811.js @@ -0,0 +1,24 @@ +/** + * @param {number[]} height + * @return {number} + */ +var maxArea = function (height) { + // 더 낮은 쪽을 안쪽으로 이동하는 방식으로 + + let start = 0; + let end = height.length - 1; + let res = -1; + while (start <= end) { + const v = Math.min(height[start], height[end]) * (end - start); + if (v > res) { + res = v; + } + + if (height[start] > height[end]) { + end -= 1; + } else { + start += 1; + } + } + return res; +}; From d175f65181a3ccd17c5ffcb52065b73c669b0122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Tue, 26 Aug 2025 11:56:22 +0900 Subject: [PATCH 3/3] design-add-and-search-words-data-structure --- .../jun0811.js | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 design-add-and-search-words-data-structure/jun0811.js diff --git a/design-add-and-search-words-data-structure/jun0811.js b/design-add-and-search-words-data-structure/jun0811.js new file mode 100644 index 0000000000..b6efcee474 --- /dev/null +++ b/design-add-and-search-words-data-structure/jun0811.js @@ -0,0 +1,65 @@ +var WordDictionary = function () { + this.trie = {}; // Trie 루트 노드 +}; + +/** + * @param {string} word + * @return {void} + */ +WordDictionary.prototype.addWord = function (word) { + let current = this.trie; + + // 각 문자마다 노드 생성 + for (let i = 0; i < word.length; i++) { + const char = word[i]; + if (!current[char]) { + current[char] = {}; + } + current = current[char]; + } + + // 단어의 끝 표시 + current.isEnd = true; +}; + +/** + * @param {string} word + * @return {boolean} + */ +WordDictionary.prototype.search = function (word) { + return dfs(word, 0, this.trie); +}; + +/** + * @param {string} word - 검색할 단어 + * @param {number} index - 현재 검사 중인 문자 인덱스 + * @param {object} node - 현재 Trie 노드 + * @return {boolean} + */ +function dfs(word, index, node) { + // 단어 끝에 도달했으면 isEnd 확인 + if (index === word.length) { + return !!node.isEnd; + } + + const char = word[index]; + + if (char === '.') { + // '.'인 경우: 모든 자식 노드를 탐색 + for (let key in node) { + if (key !== 'isEnd') { + // isEnd 속성은 제외 + if (dfs(word, index + 1, node[key])) { + return true; + } + } + } + return false; + } else { + // 일반 문자인 경우: 해당 문자의 노드로 이동 + if (!node[char]) { + return false; + } + return dfs(word, index + 1, node[char]); + } +}