From 98062a1f8b19756f63d9a2413844e4b27023944a Mon Sep 17 00:00:00 2001 From: hoyeongkwak Date: Sat, 30 Aug 2025 17:01:49 +0900 Subject: [PATCH 1/4] Week6 Solutions ver1 --- container-with-most-water/hoyeongkwak.java | 22 ++++++++++++++++++++ valid-parentheses/hoyeongkwak.java | 24 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 container-with-most-water/hoyeongkwak.java create mode 100644 valid-parentheses/hoyeongkwak.java diff --git a/container-with-most-water/hoyeongkwak.java b/container-with-most-water/hoyeongkwak.java new file mode 100644 index 000000000..49f0711d8 --- /dev/null +++ b/container-with-most-water/hoyeongkwak.java @@ -0,0 +1,22 @@ +/* +Time Complexity : O(n) +Space Complexity : O(1) +*/ +class Solution { + public int maxArea(int[] height) { + int left = 0; + int right = height.length - 1; + int area = 0; + + while (left < right) { + int currentArea = (right - left) * Math.min(height[left], height[right]); + area = Math.max(area, currentArea); + if (height[left] < height[right]) { + left++; + } else { + right--; + } + } + return area; + } +} diff --git a/valid-parentheses/hoyeongkwak.java b/valid-parentheses/hoyeongkwak.java new file mode 100644 index 000000000..1e420a278 --- /dev/null +++ b/valid-parentheses/hoyeongkwak.java @@ -0,0 +1,24 @@ +class Solution { + public boolean isValid(String s) { + if (s == null || s.length() % 2 != 0) { + return false; + } + Stack stack = new Stack<>(); + HashMap strList = new HashMap<>(); + strList.put(')', '('); + strList.put(']', '['); + strList.put('}', '{'); + + for (char c : s.toCharArray()) { + if (strList.containsKey(c)) { + if (stack.isEmpty() || stack.pop() != strList.get(c)) { + return false; + } + } else { + stack.push(c); + } + } + + return stack.isEmpty(); + } +} From c41dec1d56a08846526c190747bf806583b0d254 Mon Sep 17 00:00:00 2001 From: hoyeongkwak Date: Sat, 30 Aug 2025 17:47:24 +0900 Subject: [PATCH 2/4] week6 solution add --- .../hoyeongkwak.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 design-add-and-search-words-data-structure/hoyeongkwak.java diff --git a/design-add-and-search-words-data-structure/hoyeongkwak.java b/design-add-and-search-words-data-structure/hoyeongkwak.java new file mode 100644 index 000000000..eaadf03e9 --- /dev/null +++ b/design-add-and-search-words-data-structure/hoyeongkwak.java @@ -0,0 +1,80 @@ +/* +m : word length +n : Trie node count +addWord +Time Complexity: O(m) + +search +Time Complexity: O(n) + +Space Complexity: O(26 × N × M) + +Trie + Dfs +*/ + +class WordDictionary { + class TrieNode { + TrieNode[] children; + boolean isEnd; + + public TrieNode() { + children = new TrieNode[26]; + isEnd = false; + } + } + + private TrieNode root; + + public WordDictionary() { + root = new TrieNode(); + } + + public void addWord(String word) { + TrieNode current = root; + + for (char str : word.toCharArray()) { + int idx = str - 'a'; + if (current.children[idx] == null) { + current.children[idx] = new TrieNode(); + } + current = current.children[idx]; + } + current.isEnd = true; + } + + public boolean search(String word) { + return dfsSearch(word, 0, root); + } + + private boolean dfsSearch(String word, int idx, TrieNode node) { + if (idx == word.length()) { + return node.isEnd; + } + + char c = word.charAt(idx); + if (c == '.') { + for (int i = 0 ; i < 26; i++) { + if (node.children[i] != null) { + if (dfsSearch(word, idx + 1, node.children[i])) { + return true; + } + } + } + return false; + } else { + int charIdx = c - 'a'; + if (node.children[charIdx] == null) { + return false; + } + return dfsSearch(word, idx + 1, node.children[charIdx]); + } + } +} + +/** + * Your WordDictionary object will be instantiated and called as such: + * WordDictionary obj = new WordDictionary(); + * obj.addWord(word); + * boolean param_2 = obj.search(word); + */ + \ No newline at end of file From 8ee8cee1fe4ee4556492883061429515f03036ab Mon Sep 17 00:00:00 2001 From: hoyeongkwak Date: Mon, 1 Sep 2025 12:22:37 +0900 Subject: [PATCH 3/4] lint modify --- design-add-and-search-words-data-structure/hoyeongkwak.java | 1 + 1 file changed, 1 insertion(+) diff --git a/design-add-and-search-words-data-structure/hoyeongkwak.java b/design-add-and-search-words-data-structure/hoyeongkwak.java index eaadf03e9..6d9d8d333 100644 --- a/design-add-and-search-words-data-structure/hoyeongkwak.java +++ b/design-add-and-search-words-data-structure/hoyeongkwak.java @@ -77,4 +77,5 @@ private boolean dfsSearch(String word, int idx, TrieNode node) { * obj.addWord(word); * boolean param_2 = obj.search(word); */ + \ No newline at end of file From 599b8ab07c37c41bbf9608ec7ad427c56025ba9a Mon Sep 17 00:00:00 2001 From: hoyeongkwak Date: Mon, 1 Sep 2025 12:24:06 +0900 Subject: [PATCH 4/4] lint modify --- .../hoyeongkwak.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/design-add-and-search-words-data-structure/hoyeongkwak.java b/design-add-and-search-words-data-structure/hoyeongkwak.java index 6d9d8d333..c6b52420a 100644 --- a/design-add-and-search-words-data-structure/hoyeongkwak.java +++ b/design-add-and-search-words-data-structure/hoyeongkwak.java @@ -70,12 +70,3 @@ private boolean dfsSearch(String word, int idx, TrieNode node) { } } } - -/** - * Your WordDictionary object will be instantiated and called as such: - * WordDictionary obj = new WordDictionary(); - * obj.addWord(word); - * boolean param_2 = obj.search(word); - */ - - \ No newline at end of file