From a4ad8e972974bd89e0cea477a5e6b897490368b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Mon, 21 Jul 2025 13:42:00 +0900 Subject: [PATCH 1/5] Add contains duplicate solution --- contains-duplicate/hyunjung-choi.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 contains-duplicate/hyunjung-choi.kt diff --git a/contains-duplicate/hyunjung-choi.kt b/contains-duplicate/hyunjung-choi.kt new file mode 100644 index 0000000000..1bce83e1ea --- /dev/null +++ b/contains-duplicate/hyunjung-choi.kt @@ -0,0 +1,5 @@ +class Solution { + fun containsDuplicate(nums: IntArray): Boolean { + return nums.size != nums.toSet().size + } +} From 65592069f231efab1e946133071a5dc6eeb19eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Tue, 22 Jul 2025 07:03:10 +0900 Subject: [PATCH 2/5] Add two sum solution --- two-sum/hyunjung-choi.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 two-sum/hyunjung-choi.kt diff --git a/two-sum/hyunjung-choi.kt b/two-sum/hyunjung-choi.kt new file mode 100644 index 0000000000..856ce5dec2 --- /dev/null +++ b/two-sum/hyunjung-choi.kt @@ -0,0 +1,16 @@ +class Solution { + fun twoSum(nums: IntArray, target: Int): IntArray { + val result = IntArray(2) + + for (i in nums.indices) { + for (j in i + 1 until nums.size) { + if (nums[i] + nums[j] == target) { + result[0] = i + result[1] = j + } + } + } + + return result + } +} From d3a4c766d47ad90e0ffdb7dd523cea6b2d1242d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Wed, 23 Jul 2025 15:15:21 +0900 Subject: [PATCH 3/5] Add top K frequent elements solution --- top-k-frequent-elements/hyunjung-choi.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 top-k-frequent-elements/hyunjung-choi.kt diff --git a/top-k-frequent-elements/hyunjung-choi.kt b/top-k-frequent-elements/hyunjung-choi.kt new file mode 100644 index 0000000000..f79f6e8856 --- /dev/null +++ b/top-k-frequent-elements/hyunjung-choi.kt @@ -0,0 +1,12 @@ +class Solution { + fun topKFrequent(nums: IntArray, k: Int): IntArray { + val frequency = nums.toList().groupingBy { it }.eachCount() + + return frequency + .toList() + .sortedByDescending { it.second } + .take(k) + .map { it.first } + .toIntArray() + } +} From 50a2ffb6ba4bd512370a37fd0632fdd35fb8a707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Thu, 24 Jul 2025 13:33:22 +0900 Subject: [PATCH 4/5] Add longest consecutive sequence solution --- longest-consecutive-sequence/hyunjung-choi.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 longest-consecutive-sequence/hyunjung-choi.kt diff --git a/longest-consecutive-sequence/hyunjung-choi.kt b/longest-consecutive-sequence/hyunjung-choi.kt new file mode 100644 index 0000000000..a13ceea786 --- /dev/null +++ b/longest-consecutive-sequence/hyunjung-choi.kt @@ -0,0 +1,24 @@ +package leetcode_study + +class Solution { + fun longestConsecutive(nums: IntArray): Int { + if (nums.isEmpty()) return 0 + + val sortedNums = nums.sorted() + var maxLength = 1 + var currentLength = 1 + + for (i in 1 until sortedNums.size) { + when { + sortedNums[i] == sortedNums[i - 1] -> continue + sortedNums[i] == sortedNums[i - 1] + 1 -> { + currentLength++ + maxLength = maxOf(maxLength, currentLength) + } + else -> currentLength = 1 + } + } + + return maxLength + } +} From f43803c833c2d42608411a7c41627a9ef95dd822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Fri, 25 Jul 2025 14:26:02 +0900 Subject: [PATCH 5/5] Add house robber solution --- house-robber/hyunjung-choi.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 house-robber/hyunjung-choi.kt diff --git a/house-robber/hyunjung-choi.kt b/house-robber/hyunjung-choi.kt new file mode 100644 index 0000000000..b75c8ef0a1 --- /dev/null +++ b/house-robber/hyunjung-choi.kt @@ -0,0 +1,18 @@ +package leetcode_study + +class Solution { + fun rob(nums: IntArray): Int { + if (nums.size == 1) return nums[0] + + var prev2 = nums[0] + var prev1 = maxOf(nums[0], nums[1]) + + for (i in 2 until nums.size) { + val current = maxOf(prev1, prev2 + nums[i]) + prev2 = prev1 + prev1 = current + } + + return prev1 + } +}