From 6aadb4bba5d6d7c4c1cbf0983e23c095bddf0b83 Mon Sep 17 00:00:00 2001 From: soobing Date: Sun, 5 Apr 2026 10:29:06 +0900 Subject: [PATCH 1/7] feat: best-time-to-buy-and-sell-stock --- best-time-to-buy-and-sell-stock/soobing3.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/soobing3.ts diff --git a/best-time-to-buy-and-sell-stock/soobing3.ts b/best-time-to-buy-and-sell-stock/soobing3.ts new file mode 100644 index 0000000000..373f8fec06 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/soobing3.ts @@ -0,0 +1,15 @@ +function maxProfit(prices: number[]): number { + let left = 0; + let right = 1; + let max = 0; + + while(left < right && right < prices.length) { + if(prices[right] - prices[left] > 0) { + max = Math.max(max, prices[right] - prices[left]) + } else { + left = right; + } + right++; + } + return max; +}; From 61e5e54351f96cb3350ebb29b88ea07d34504452 Mon Sep 17 00:00:00 2001 From: soobing Date: Sun, 5 Apr 2026 10:38:50 +0900 Subject: [PATCH 2/7] feat: group-anagrams --- group-anagrams/soobing3.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 group-anagrams/soobing3.ts diff --git a/group-anagrams/soobing3.ts b/group-anagrams/soobing3.ts new file mode 100644 index 0000000000..3763f3e452 --- /dev/null +++ b/group-anagrams/soobing3.ts @@ -0,0 +1,10 @@ +function groupAnagrams(strs: string[]): string[][] { + const map = new Map(); + + for(const str of strs) { + const key = str.split('').sort().join(''); + const value = map.get(key); + map.set(key, value ? [...value, str] : [str]) + } + return Array.from(map.values()); +}; From 7161650d6f437450de992b7a5164627718a9adff Mon Sep 17 00:00:00 2001 From: soobing Date: Sun, 5 Apr 2026 20:39:22 +0900 Subject: [PATCH 3/7] feat: encode-and-decode-strings --- encode-and-decode-strings/soobing3.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 encode-and-decode-strings/soobing3.ts diff --git a/encode-and-decode-strings/soobing3.ts b/encode-and-decode-strings/soobing3.ts new file mode 100644 index 0000000000..e1b8dc8d29 --- /dev/null +++ b/encode-and-decode-strings/soobing3.ts @@ -0,0 +1,25 @@ +class Solution { + /** + * @param {string[]} strs + * @returns {string} + */ + encode(strs) { + return strs.map((str) => `${str.length}#${str}`).join(''); + } + + /** + * @param {string} str + * @returns {string[]} + */ + decode(str) { + const result: string[] = []; + let i = 0; + while(i < str.length) { + const j = str.indexOf('#', i); + const length = Number(str.slice(i, j)); + result.push(str.slice(j + 1, j + 1 + length)); + i = j + 1 + length; + } + return result; + } +} From 58b8612bd30f132dbd2cbbfeb4bd76a556f89755 Mon Sep 17 00:00:00 2001 From: soobing Date: Sun, 5 Apr 2026 21:47:09 +0900 Subject: [PATCH 4/7] feat: implement-trie-prefix-tree --- implement-trie-prefix-tree/soobing3.ts | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 implement-trie-prefix-tree/soobing3.ts diff --git a/implement-trie-prefix-tree/soobing3.ts b/implement-trie-prefix-tree/soobing3.ts new file mode 100644 index 0000000000..0343ccfbcb --- /dev/null +++ b/implement-trie-prefix-tree/soobing3.ts @@ -0,0 +1,52 @@ +class TrieNode { + children: Map; + isEnd: boolean; + constructor() { + this.children = new Map(); + this.isEnd = false + } +} +class Trie { + root: TrieNode; + + constructor() { + this.root = new TrieNode(); + } + + insert(word: string): void { + let node = this.root; + for(const ch of word) { + if(!node.children.has(ch)) { + node.children.set(ch, new TrieNode()); + } + node = node.children.get(ch)! + } + node.isEnd = true; + } + + search(word: string): boolean { + let node = this.root; + for(const ch of word) { + if(!node.children.has(ch)) return false; + node = node.children.get(ch)!; + } + return node.isEnd; + } + + startsWith(prefix: string): boolean { + let node = this.root; + for(const ch of prefix) { + if(!node.children.has(ch)) return false; + node = node.children.get(ch)!; + } + return true; + } +} + +/** +* Your Trie object will be instantiated and called as such: +* var obj = new Trie() +* obj.insert(word) +* var param_2 = obj.search(word) +* var param_3 = obj.startsWith(prefix) +*/ From 7f20e49d19a892d5cb9b6782f71995abd13c6691 Mon Sep 17 00:00:00 2001 From: soobing Date: Sun, 5 Apr 2026 21:59:34 +0900 Subject: [PATCH 5/7] feat: word-break --- word-break/soobing3.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 word-break/soobing3.ts diff --git a/word-break/soobing3.ts b/word-break/soobing3.ts new file mode 100644 index 0000000000..42e3b0743f --- /dev/null +++ b/word-break/soobing3.ts @@ -0,0 +1,15 @@ +function wordBreak(s: string, wordDict: string[]): boolean { + const dp = new Array(s.length + 1).fill(false); + dp[0] = true; + + for (let i = 1; i <= s.length; i++) { + for (let j = 0; j < i; j++) { + if (dp[j] && wordDict.includes(s.slice(j, i))) { + dp[i] = true; + break; + } + } + } + + return dp[s.length]; +}; From 23df2b7df955efdb93405f4f9817a158661df3ae Mon Sep 17 00:00:00 2001 From: soobing Date: Mon, 6 Apr 2026 22:04:05 +0900 Subject: [PATCH 6/7] fix: lint --- implement-trie-prefix-tree/soobing3.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/implement-trie-prefix-tree/soobing3.ts b/implement-trie-prefix-tree/soobing3.ts index 0343ccfbcb..d8cfd5d97c 100644 --- a/implement-trie-prefix-tree/soobing3.ts +++ b/implement-trie-prefix-tree/soobing3.ts @@ -50,3 +50,4 @@ class Trie { * var param_2 = obj.search(word) * var param_3 = obj.startsWith(prefix) */ + From 9a45a0dcd81037a9d97f13a21f4df3a1dcdc5f80 Mon Sep 17 00:00:00 2001 From: soobing Date: Mon, 6 Apr 2026 22:12:47 +0900 Subject: [PATCH 7/7] feat(soobing): move 3rd tried solutions to soobing.ts --- best-time-to-buy-and-sell-stock/soobing.ts | 24 ++++----- best-time-to-buy-and-sell-stock/soobing3.ts | 15 ------ encode-and-decode-strings/soobing.ts | 40 ++++++--------- encode-and-decode-strings/soobing3.ts | 25 ---------- group-anagrams/soobing.ts | 20 +++----- group-anagrams/soobing3.ts | 10 ---- implement-trie-prefix-tree/soobing.ts | 55 ++++++++++++--------- implement-trie-prefix-tree/soobing3.ts | 53 -------------------- word-break/soobing.ts | 23 ++++----- word-break/soobing3.ts | 15 ------ 10 files changed, 80 insertions(+), 200 deletions(-) delete mode 100644 best-time-to-buy-and-sell-stock/soobing3.ts delete mode 100644 encode-and-decode-strings/soobing3.ts delete mode 100644 group-anagrams/soobing3.ts delete mode 100644 implement-trie-prefix-tree/soobing3.ts delete mode 100644 word-break/soobing3.ts diff --git a/best-time-to-buy-and-sell-stock/soobing.ts b/best-time-to-buy-and-sell-stock/soobing.ts index b30c33976b..e83e6469f0 100644 --- a/best-time-to-buy-and-sell-stock/soobing.ts +++ b/best-time-to-buy-and-sell-stock/soobing.ts @@ -1,14 +1,16 @@ +// 3rd tried function maxProfit(prices: number[]): number { - let minPrice = Infinity; - let maxProfit = 0; - for (let i = 0; i < prices.length; i++) { - if (prices[i] < minPrice) { - minPrice = prices[i]; - } + let left = 0; + let right = 1; + let max = 0; - if (prices[i] - minPrice > maxProfit) { - maxProfit = prices[i] - minPrice; - } + while(left < right && right < prices.length) { + if(prices[right] - prices[left] > 0) { + max = Math.max(max, prices[right] - prices[left]) + } else { + left = right; + } + right++; } - return maxProfit; -} + return max; +}; diff --git a/best-time-to-buy-and-sell-stock/soobing3.ts b/best-time-to-buy-and-sell-stock/soobing3.ts deleted file mode 100644 index 373f8fec06..0000000000 --- a/best-time-to-buy-and-sell-stock/soobing3.ts +++ /dev/null @@ -1,15 +0,0 @@ -function maxProfit(prices: number[]): number { - let left = 0; - let right = 1; - let max = 0; - - while(left < right && right < prices.length) { - if(prices[right] - prices[left] > 0) { - max = Math.max(max, prices[right] - prices[left]) - } else { - left = right; - } - right++; - } - return max; -}; diff --git a/encode-and-decode-strings/soobing.ts b/encode-and-decode-strings/soobing.ts index e3b471b12b..89bb0811d6 100644 --- a/encode-and-decode-strings/soobing.ts +++ b/encode-and-decode-strings/soobing.ts @@ -1,34 +1,26 @@ +// 3rd tried class Solution { /** - * 문자열 배열을 하나의 문자열로 인코딩합니다. - * @param strs - 문자열 배열 - * @returns 인코딩된 하나의 문자열 + * @param {string[]} strs + * @returns {string} */ - encode(strs: string[]): string { - return strs.map((str) => str.length + "#" + str).join(""); + encode(strs) { + return strs.map((str) => `${str.length}#${str}`).join(''); } /** - * 인코딩된 문자열을 원래 문자열 배열로 디코딩합니다. - * @param str - 인코딩된 문자열 - * @returns 디코딩된 문자열 배열 + * @param {string} str + * @returns {string[]} */ - decode(str: string): string[] { - const result: string[] = []; - - let i = 0; - while (i < str.length) { - let j = i; - while (str[j] !== "#") { - j++; + decode(str) { + const result: string[] = []; + let i = 0; + while(i < str.length) { + const j = str.indexOf('#', i); + const length = Number(str.slice(i, j)); + result.push(str.slice(j + 1, j + 1 + length)); + i = j + 1 + length; } - - const length = parseInt(str.slice(i, j)); - const word = str.slice(j + 1, j + 1 + length); - result.push(word); - i = j + 1 + length; - } - - return result; + return result; } } diff --git a/encode-and-decode-strings/soobing3.ts b/encode-and-decode-strings/soobing3.ts deleted file mode 100644 index e1b8dc8d29..0000000000 --- a/encode-and-decode-strings/soobing3.ts +++ /dev/null @@ -1,25 +0,0 @@ -class Solution { - /** - * @param {string[]} strs - * @returns {string} - */ - encode(strs) { - return strs.map((str) => `${str.length}#${str}`).join(''); - } - - /** - * @param {string} str - * @returns {string[]} - */ - decode(str) { - const result: string[] = []; - let i = 0; - while(i < str.length) { - const j = str.indexOf('#', i); - const length = Number(str.slice(i, j)); - result.push(str.slice(j + 1, j + 1 + length)); - i = j + 1 + length; - } - return result; - } -} diff --git a/group-anagrams/soobing.ts b/group-anagrams/soobing.ts index c446e01609..ecad1e2a6e 100644 --- a/group-anagrams/soobing.ts +++ b/group-anagrams/soobing.ts @@ -1,15 +1,11 @@ -// idea: 배열에 담긴 모든 애들을 다 sorting하면서 sorting된 결과를 key로 바인딩하고 Record 에 맞게 매핑하여 values들만 리턴하면 될것 같음 +// 3rd tried function groupAnagrams(strs: string[]): string[][] { - const map = new Map(); + const map = new Map(); - for (let i = 0; i < strs.length; i++) { - const key = strs[i].split("").sort().join(""); - const group = map.get(key); - if (group) { - group.push(strs[i]); - } else { - map.set(key, [strs[i]]); - } + for(const str of strs) { + const key = str.split('').sort().join(''); + const value = map.get(key); + map.set(key, value ? [...value, str] : [str]) } - return [...map.values()]; -} + return Array.from(map.values()); +}; diff --git a/group-anagrams/soobing3.ts b/group-anagrams/soobing3.ts deleted file mode 100644 index 3763f3e452..0000000000 --- a/group-anagrams/soobing3.ts +++ /dev/null @@ -1,10 +0,0 @@ -function groupAnagrams(strs: string[]): string[][] { - const map = new Map(); - - for(const str of strs) { - const key = str.split('').sort().join(''); - const value = map.get(key); - map.set(key, value ? [...value, str] : [str]) - } - return Array.from(map.values()); -}; diff --git a/implement-trie-prefix-tree/soobing.ts b/implement-trie-prefix-tree/soobing.ts index d6a9e59359..6d0a72d12e 100644 --- a/implement-trie-prefix-tree/soobing.ts +++ b/implement-trie-prefix-tree/soobing.ts @@ -1,46 +1,53 @@ +// 3rd tried class TrieNode { children: Map; isEnd: boolean; - constructor() { - this.children = new Map(); - this.isEnd = false; + this.children = new Map(); + this.isEnd = false } } - class Trie { root: TrieNode; constructor() { - this.root = new TrieNode(); + this.root = new TrieNode(); } insert(word: string): void { - let node = this.root; - for (const char of word) { - if (!node.children.has(char)) { - node.children.set(char, new TrieNode()); + let node = this.root; + for(const ch of word) { + if(!node.children.has(ch)) { + node.children.set(ch, new TrieNode()); + } + node = node.children.get(ch)! } - node = node.children.get(char)!; - } - node.isEnd = true; + node.isEnd = true; } search(word: string): boolean { - const node = this._findNode(word); - return node !== null && node.isEnd; + let node = this.root; + for(const ch of word) { + if(!node.children.has(ch)) return false; + node = node.children.get(ch)!; + } + return node.isEnd; } startsWith(prefix: string): boolean { - return this._findNode(prefix) !== null; - } - - private _findNode(word: string): TrieNode | null { - let node = this.root; - for (const char of word) { - if (!node.children.has(char)) return null; - node = node.children.get(char)!; - } - return node; + let node = this.root; + for(const ch of prefix) { + if(!node.children.has(ch)) return false; + node = node.children.get(ch)!; + } + return true; } } + +/** +* Your Trie object will be instantiated and called as such: +* var obj = new Trie() +* obj.insert(word) +* var param_2 = obj.search(word) +* var param_3 = obj.startsWith(prefix) +*/ diff --git a/implement-trie-prefix-tree/soobing3.ts b/implement-trie-prefix-tree/soobing3.ts deleted file mode 100644 index d8cfd5d97c..0000000000 --- a/implement-trie-prefix-tree/soobing3.ts +++ /dev/null @@ -1,53 +0,0 @@ -class TrieNode { - children: Map; - isEnd: boolean; - constructor() { - this.children = new Map(); - this.isEnd = false - } -} -class Trie { - root: TrieNode; - - constructor() { - this.root = new TrieNode(); - } - - insert(word: string): void { - let node = this.root; - for(const ch of word) { - if(!node.children.has(ch)) { - node.children.set(ch, new TrieNode()); - } - node = node.children.get(ch)! - } - node.isEnd = true; - } - - search(word: string): boolean { - let node = this.root; - for(const ch of word) { - if(!node.children.has(ch)) return false; - node = node.children.get(ch)!; - } - return node.isEnd; - } - - startsWith(prefix: string): boolean { - let node = this.root; - for(const ch of prefix) { - if(!node.children.has(ch)) return false; - node = node.children.get(ch)!; - } - return true; - } -} - -/** -* Your Trie object will be instantiated and called as such: -* var obj = new Trie() -* obj.insert(word) -* var param_2 = obj.search(word) -* var param_3 = obj.startsWith(prefix) -*/ - diff --git a/word-break/soobing.ts b/word-break/soobing.ts index a6ed583068..f6925e063a 100644 --- a/word-break/soobing.ts +++ b/word-break/soobing.ts @@ -1,15 +1,16 @@ +// 3rd tried function wordBreak(s: string, wordDict: string[]): boolean { const dp = new Array(s.length + 1).fill(false); - dp[s.length] = true; + dp[0] = true; - for (let i = s.length - 1; i >= 0; i--) { - for (const word of wordDict) { - if (i + word.length <= s.length && s.slice(i, i + word.length) === word) { - dp[i] = dp[i + word.length]; - } - - if (dp[i]) break; + for (let i = 1; i <= s.length; i++) { + for (let j = 0; j < i; j++) { + if (dp[j] && wordDict.includes(s.slice(j, i))) { + dp[i] = true; + break; + } + } } - } - return dp[0]; -} + + return dp[s.length]; +}; diff --git a/word-break/soobing3.ts b/word-break/soobing3.ts deleted file mode 100644 index 42e3b0743f..0000000000 --- a/word-break/soobing3.ts +++ /dev/null @@ -1,15 +0,0 @@ -function wordBreak(s: string, wordDict: string[]): boolean { - const dp = new Array(s.length + 1).fill(false); - dp[0] = true; - - for (let i = 1; i <= s.length; i++) { - for (let j = 0; j < i; j++) { - if (dp[j] && wordDict.includes(s.slice(j, i))) { - dp[i] = true; - break; - } - } - } - - return dp[s.length]; -};