From b263e248b4f3f48d91d71ddb7837ffc267cd4cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Mon, 25 Aug 2025 12:08:20 +0900 Subject: [PATCH 1/4] Add valid parentheses solution --- valid-parentheses/hyunjung-choi.kt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 valid-parentheses/hyunjung-choi.kt diff --git a/valid-parentheses/hyunjung-choi.kt b/valid-parentheses/hyunjung-choi.kt new file mode 100644 index 000000000..2b750b98c --- /dev/null +++ b/valid-parentheses/hyunjung-choi.kt @@ -0,0 +1,27 @@ +/** + * 시간 복잡도: O(n) + * 공간 복잡도: O(n) + */ + +class Solution { + fun isValid(s: String): Boolean { + if (s.length % 2 == 1) return false + + val stack = Stack() + val pairs = mapOf(')' to '(', ']' to '[', '}' to '{') + + for (char in s) { + when { + char in pairs -> { + if (stack.isEmpty() || stack.pop() != pairs[char]) { + return false + } + } + + else -> stack.push(char) + } + } + + return stack.isEmpty() + } +} From 791de24daa399c57640823a86973246c848aa5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Wed, 27 Aug 2025 13:57:28 +0900 Subject: [PATCH 2/4] Add container with most water solution --- container-with-most-water/hyunjung-choi.kt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 container-with-most-water/hyunjung-choi.kt diff --git a/container-with-most-water/hyunjung-choi.kt b/container-with-most-water/hyunjung-choi.kt new file mode 100644 index 000000000..9ca6cb2b3 --- /dev/null +++ b/container-with-most-water/hyunjung-choi.kt @@ -0,0 +1,22 @@ +/** + * 시간 복잡도: O(n) + * 공간 복잡도: O(1) + */ + +class Solution { + fun maxArea(height: IntArray): Int { + var i = 0 + var j = height.size - 1 + var max = 0 + + while (i < j) { + val h = minOf(height[i], height[j]) + max = maxOf(max, (j - i) * h) + + if (height[i] <= height[j]) i++ + else j-- + } + + return max + } +} From 45f9d49188ebf9f457f1b54380b4c869df4fbb27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Fri, 29 Aug 2025 22:51:47 +0900 Subject: [PATCH 3/4] Add design add and search words data structure solution --- .../hyunjung-choi.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 design-add-and-search-words-data-structure/hyunjung-choi.kt diff --git a/design-add-and-search-words-data-structure/hyunjung-choi.kt b/design-add-and-search-words-data-structure/hyunjung-choi.kt new file mode 100644 index 000000000..ac63acef3 --- /dev/null +++ b/design-add-and-search-words-data-structure/hyunjung-choi.kt @@ -0,0 +1,46 @@ +class WordDictionary() { + + class TrieNode { + val children = mutableMapOf() + var isEndOfWord = false + } + + private val root = TrieNode() + + fun addWord(word: String) { + var current = root + + for (char in word) { + if (char !in current.children) { + current.children[char] = TrieNode() + } + current = current.children[char]!! + } + + current.isEndOfWord = true + } + + fun search(word: String): Boolean { + return searchHelper(word, 0, root) + } + + private fun searchHelper(word: String, index: Int, node: TrieNode): Boolean { + if (index == word.length) { + return node.isEndOfWord + } + + val char = word[index] + + return if (char == '.') { + for (child in node.children.values) { + if (searchHelper(word, index + 1, child)) { + return true + } + } + false + } else { + val child = node.children[char] ?: return false + searchHelper(word, index + 1, child) + } + } +} From 9265fe31f64c74199db658a1572a5e99151c8030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Sat, 30 Aug 2025 14:04:15 +0900 Subject: [PATCH 4/4] Add longest increasing subsequence solution --- .../hyunjung-choi.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 longest-increasing-subsequence/hyunjung-choi.kt diff --git a/longest-increasing-subsequence/hyunjung-choi.kt b/longest-increasing-subsequence/hyunjung-choi.kt new file mode 100644 index 000000000..ac9a787ae --- /dev/null +++ b/longest-increasing-subsequence/hyunjung-choi.kt @@ -0,0 +1,33 @@ +class Solution { + fun lengthOfLIS(nums: IntArray): Int { + val tails = mutableListOf() + + for (num in nums) { + val pos = binarySearchLeftmost(tails, num) + + if (pos == tails.size) { + tails.add(num) + } else { + tails[pos] = num + } + } + + return tails.size + } + + fun binarySearchLeftmost(list: List, target: Int): Int { + var left = 0 + var right = list.size + + while (left < right) { + val mid = left + (right - left) / 2 + if (list[mid] < target) { + left = mid + 1 + } else { + right = mid + } + } + + return left + } +}