From 6e98ee96448bde71bff95f91b0ec66c0dba5012d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Mon, 28 Jul 2025 12:45:02 +0900 Subject: [PATCH 1/5] Add valid anagram solution --- valid-anagram/hyunjung-choi.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 valid-anagram/hyunjung-choi.kt diff --git a/valid-anagram/hyunjung-choi.kt b/valid-anagram/hyunjung-choi.kt new file mode 100644 index 000000000..4357915c6 --- /dev/null +++ b/valid-anagram/hyunjung-choi.kt @@ -0,0 +1,19 @@ +class Solution { + fun isAnagram(s: String, t: String): Boolean { + if (s.length != t.length) return false + + val charCount = mutableMapOf() + + s.forEach { ch -> + charCount.put(ch, charCount.getOrDefault(ch, 0) + 1) + } + + t.forEach { ch -> + val count = charCount.getOrDefault(ch, 0) + if (count == 0) return false + charCount[ch] = count - 1 + } + + return true + } +} From bf973312eeb46afb49872f00c74978f59a62a9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Tue, 29 Jul 2025 15:35:51 +0900 Subject: [PATCH 2/5] Add climb stairs solution --- climbing-stairs/hyunjung-choi.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 climbing-stairs/hyunjung-choi.kt diff --git a/climbing-stairs/hyunjung-choi.kt b/climbing-stairs/hyunjung-choi.kt new file mode 100644 index 000000000..cadcc083a --- /dev/null +++ b/climbing-stairs/hyunjung-choi.kt @@ -0,0 +1,16 @@ +class Solution { + fun climbStairs(n: Int): Int { + if (n <= 2) return n + + var prev2 = 1 + var prev1 = 2 + + for (i in 3..n) { + val current = prev1 + prev2 + prev2 = prev1 + prev1 = current + } + + return prev1 + } +} From 0999d34bef59e56f49dd414669833c624845cc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Wed, 30 Jul 2025 12:09:42 +0900 Subject: [PATCH 3/5] Add product of array except self solution --- product-of-array-except-self/hyunjung-choi.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 product-of-array-except-self/hyunjung-choi.kt diff --git a/product-of-array-except-self/hyunjung-choi.kt b/product-of-array-except-self/hyunjung-choi.kt new file mode 100644 index 000000000..1ac22486c --- /dev/null +++ b/product-of-array-except-self/hyunjung-choi.kt @@ -0,0 +1,16 @@ +class Solution { + fun productExceptSelf(nums: IntArray): IntArray = + IntArray(nums.size) { 1 }.apply { + var leftProduct = 1 + for (i in 1 until nums.size) { + leftProduct *= nums[i - 1] + this[i] = leftProduct + } + + var rightProduct = 1 + for (i in nums.size - 2 downTo 0) { + rightProduct *= nums[i + 1] + this[i] *= rightProduct + } + } +} From a005de9e565e9131c0fffe0df50c8bc28d38c88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Thu, 31 Jul 2025 14:30:04 +0900 Subject: [PATCH 4/5] Add three sum solution --- 3sum/hyunjung-choi.kt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 3sum/hyunjung-choi.kt diff --git a/3sum/hyunjung-choi.kt b/3sum/hyunjung-choi.kt new file mode 100644 index 000000000..1aff4131c --- /dev/null +++ b/3sum/hyunjung-choi.kt @@ -0,0 +1,35 @@ +class Solution { + fun threeSum(nums: IntArray): List> { + if (nums.size < 3) return emptyList() + + val result = mutableSetOf>() + + nums.sort() + + for (i in 0 until nums.size - 2) { + + if (i > 0 && nums[i] == nums[i - 1]) continue + + var left = i + 1 + var right = nums.size - 1 + + while (left < right) { + val sum = nums[i] + nums[left] + nums[right] + + when { + sum == 0 -> { + result.add(listOf(nums[i], nums[left], nums[right])) + + left++ + right-- + } + + sum < 0 -> left++ + else -> right-- + } + } + } + + return result.toList() + } +} From 8e0008d99174739ab1af0d2e1079268cac511ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Fri, 1 Aug 2025 17:43:12 +0900 Subject: [PATCH 5/5] Add validate binary search tree solution --- validate-binary-search-tree/hyunjung-choi.kt | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 validate-binary-search-tree/hyunjung-choi.kt diff --git a/validate-binary-search-tree/hyunjung-choi.kt b/validate-binary-search-tree/hyunjung-choi.kt new file mode 100644 index 000000000..0bce34a62 --- /dev/null +++ b/validate-binary-search-tree/hyunjung-choi.kt @@ -0,0 +1,30 @@ +/** + * Example: + * var ti = TreeNode(5) + * var v = ti.`val` + * Definition for a binary tree node. + * class TreeNode(var `val`: Int) { + * var left: TreeNode? = null + * var right: TreeNode? = null + * } + */ +class Solution { + fun isValidBST(root: TreeNode?): Boolean { + val values = mutableListOf() + inorderTraversal(root, values) + + for (i in 1 until values.size) { + if (values[i] <= values[i - 1]) return false + } + + return true + } + + private fun inorderTraversal(root: TreeNode?, values: MutableList) { + if (root == null) return + + inorderTraversal(root.left, values) + values.add(root.`val`) + inorderTraversal(root.right, values) + } +}