From d2f40e984b9c9dce10c9caea1382b94bc3e85196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Tue, 9 Dec 2025 14:04:55 +0000 Subject: [PATCH 1/7] best time to buy and sell stock solution --- best-time-to-buy-and-sell-stock/hyunolike.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/hyunolike.java diff --git a/best-time-to-buy-and-sell-stock/hyunolike.java b/best-time-to-buy-and-sell-stock/hyunolike.java new file mode 100644 index 0000000000..cd39041d68 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/hyunolike.java @@ -0,0 +1,14 @@ +class Solution { + public int maxProfit(int[] prices) { + // 주식 최대 이익 + int minPrice = Integer.MAX_VALUE; + int maxProfit = 0; + + for (int price : prices) { + minPrice = Math.min(minPrice, price); + maxProfit = Math.max(maxProfit, price - minPrice); + } + + return maxProfit; + } +} From aac2106f792ec4a0148fe21657aa4495c6571e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Tue, 9 Dec 2025 14:05:48 +0000 Subject: [PATCH 2/7] group anagrams solution --- group-anagrams/hyunolike.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 group-anagrams/hyunolike.java diff --git a/group-anagrams/hyunolike.java b/group-anagrams/hyunolike.java new file mode 100644 index 0000000000..1dec22a661 --- /dev/null +++ b/group-anagrams/hyunolike.java @@ -0,0 +1,22 @@ +class Solution { + public List> groupAnagrams(String[] strs) { + // 같은 문자열 끼리 묶기 + // 그룹이 가장 적은 순으로 정렬 + + Map> map = new HashMap<>(); + + // 각 문자열 char로 바꿔서 정렬하고 다시 문자열 + for(String str : strs) { + char[] arr = str.toCharArray(); + Arrays.sort(arr); + + String key = new String(arr); // 정렬된 문자열 키로 하기 + + map.computeIfAbsent(key, k -> new ArrayList<>()).add(str); + } + + return new ArrayList<>(map.values()); + // map 자료구조, 정렬까지 생각 + // 이후 프로세스 생각 어려움 + } +} From 0ac9b42a1d9467f606b8a2655b1ac6c79c370375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Wed, 10 Dec 2025 13:34:14 +0000 Subject: [PATCH 3/7] implement trie prefix tree solution --- implement-trie-prefix-tree/hyunolike.java | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 implement-trie-prefix-tree/hyunolike.java diff --git a/implement-trie-prefix-tree/hyunolike.java b/implement-trie-prefix-tree/hyunolike.java new file mode 100644 index 0000000000..5f8f927ef8 --- /dev/null +++ b/implement-trie-prefix-tree/hyunolike.java @@ -0,0 +1,54 @@ +class TrieNode { + TrieNode[] children = new TrieNode[26]; + boolean isEnd; +} + +class Trie { + + private TrieNode root; + + public Trie() { + root = new TrieNode(); + } + + public void insert(String word) { + TrieNode node = root; + for (char c : word.toCharArray()) { + int idx = c - 'a'; + if(node.children[idx] == null) { + node.children[idx] = new TrieNode(); + } + node = node.children[idx]; + } + node.isEnd = true; + } + + public boolean search(String word) { + TrieNode node = root; + for(char c : word.toCharArray()) { + int idx = c - 'a'; + if(node.children[idx] == null) return false; + node = node.children[idx]; + } + + return node.isEnd; + } + + public boolean startsWith(String prefix) { + TrieNode node = root; + for(char c : prefix.toCharArray()) { + int idx = c - 'a'; + if(node.children[idx] == null) return false; + node = node.children[idx]; + } + return true; + } +} + +/** + * Your Trie object will be instantiated and called as such: + * Trie obj = new Trie(); + * obj.insert(word); + * boolean param_2 = obj.search(word); + * boolean param_3 = obj.startsWith(prefix); + */ \ No newline at end of file From 40601e8cb1a0aaaa4be6b253f16e81171f7782df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Wed, 10 Dec 2025 13:42:31 +0000 Subject: [PATCH 4/7] word break solution --- word-break/hyunolike.java | 19 +++++++++++++++++++ word-break/hyunolike.ts | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 word-break/hyunolike.java create mode 100644 word-break/hyunolike.ts diff --git a/word-break/hyunolike.java b/word-break/hyunolike.java new file mode 100644 index 0000000000..fe8717ee91 --- /dev/null +++ b/word-break/hyunolike.java @@ -0,0 +1,19 @@ +class Solution { + public boolean wordBreak(String s, List wordDict) { + int n = s.length(); + boolean[] dp = new boolean[n+1]; + dp[0] = true; + + Set wordSet = new HashSet<>(wordDict); + + for(int i = 1; i <= n; i++) { + for(int j = 0; j < i; j++) { + if(dp[j] && wordSet.contains(s.substring(j, i))) { + dp[i] = true; + break; + } + } + } + return dp[n]; + } +} \ No newline at end of file diff --git a/word-break/hyunolike.ts b/word-break/hyunolike.ts new file mode 100644 index 0000000000..5ab5c68cbf --- /dev/null +++ b/word-break/hyunolike.ts @@ -0,0 +1,17 @@ +function wordBreak(s: string, wordDict: string[]): boolean { + const n = s.length; + const dp:boolean[] = Array(n+1).fill(false); + dp[0] = true; + + const wordSet = new Set(wordDict); + + for(let i = 1; i <= n; i++) { + for(let j = 0; j < i; j++) { + if(dp[j] && wordSet.has(s.substring(j, i))) { + dp[i] = true; + break; + } + } + } + return dp[n]; +}; \ No newline at end of file From 3c3ba5bc54ac04c18df52b115aa082f9c3d20bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Wed, 10 Dec 2025 13:48:31 +0000 Subject: [PATCH 5/7] encode and decode strings solution --- encode-and-decode-strings/hyunolike.java | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 encode-and-decode-strings/hyunolike.java diff --git a/encode-and-decode-strings/hyunolike.java b/encode-and-decode-strings/hyunolike.java new file mode 100644 index 0000000000..b64fe318c1 --- /dev/null +++ b/encode-and-decode-strings/hyunolike.java @@ -0,0 +1,38 @@ +public class Codec { + + // Encodes a list of strings to a single string. + public String encode(List strs) { + StringBuilder sb = new StringBuilder(); + + for (String s : strs) { + sb.append(s.length()).append('#').append(s); + } + + return sb.toString(); + } + + // Decodes a single string to a list of strings. + public List decode(String s) { + List res = new ArrayList<>(); + int i = 0; + + while (i < s.length()) { + int j = i; + + // find '#' + while (s.charAt(j) != '#') { + j++; + } + + int length = Integer.parseInt(s.substring(i, j)); + j++; // move past '#' + + String word = s.substring(j, j + length); + res.add(word); + + i = j + length; // move to next encoded segment + } + + return res; + } +} From 3551259104f061946f73e25fbf0f4d59463bd171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Wed, 10 Dec 2025 13:51:16 +0000 Subject: [PATCH 6/7] =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=20=EC=88=98=EC=A0=95=20(=EA=B9=83=ED=97=88=EB=B8=8C?= =?UTF-8?q?=20=EC=97=91=EC=85=98=20=EC=9D=B4=EC=8A=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- encode-and-decode-strings/hyunolike.java | 1 + implement-trie-prefix-tree/hyunolike.java | 3 ++- word-break/hyunolike.java | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/encode-and-decode-strings/hyunolike.java b/encode-and-decode-strings/hyunolike.java index b64fe318c1..8839fac545 100644 --- a/encode-and-decode-strings/hyunolike.java +++ b/encode-and-decode-strings/hyunolike.java @@ -36,3 +36,4 @@ public List decode(String s) { return res; } } + diff --git a/implement-trie-prefix-tree/hyunolike.java b/implement-trie-prefix-tree/hyunolike.java index 5f8f927ef8..b53371f2ce 100644 --- a/implement-trie-prefix-tree/hyunolike.java +++ b/implement-trie-prefix-tree/hyunolike.java @@ -51,4 +51,5 @@ public boolean startsWith(String prefix) { * obj.insert(word); * boolean param_2 = obj.search(word); * boolean param_3 = obj.startsWith(prefix); - */ \ No newline at end of file + */ + diff --git a/word-break/hyunolike.java b/word-break/hyunolike.java index fe8717ee91..0bf282749d 100644 --- a/word-break/hyunolike.java +++ b/word-break/hyunolike.java @@ -16,4 +16,5 @@ public boolean wordBreak(String s, List wordDict) { } return dp[n]; } -} \ No newline at end of file +} + From 7d530fe9a2ab1a06dd1dad055c60ad0b05b9fdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Wed, 10 Dec 2025 13:52:22 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=20=EC=88=98=EC=A0=95=20(=EA=B9=83=ED=97=88=EB=B8=8C?= =?UTF-8?q?=20=EC=97=91=EC=85=98=20=EC=9D=B4=EC=8A=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- word-break/hyunolike.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/word-break/hyunolike.ts b/word-break/hyunolike.ts index 5ab5c68cbf..6b5390e1c8 100644 --- a/word-break/hyunolike.ts +++ b/word-break/hyunolike.ts @@ -14,4 +14,4 @@ function wordBreak(s: string, wordDict: string[]): boolean { } } return dp[n]; -}; \ No newline at end of file +};