From 2b9e65cb260e865422d081bed0f02b8dcb2345f7 Mon Sep 17 00:00:00 2001 From: ace kim Date: Tue, 3 Mar 2026 00:10:15 +0800 Subject: [PATCH 1/5] solve Contains Duplicate --- contains-duplicate/acious.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 contains-duplicate/acious.kt diff --git a/contains-duplicate/acious.kt b/contains-duplicate/acious.kt new file mode 100644 index 0000000000..b22f8dad06 --- /dev/null +++ b/contains-duplicate/acious.kt @@ -0,0 +1,16 @@ +class Solution { + // 1 <= nums.length <= 10^5 + // Integer.MIN_VALUE(2,147,483,647) < -10^9 <= nums[i] <= 10^9 < Integer.MAX_VALUE(2,147,483,647) + // HashSet에 아이템을 하나씩 넣으면서 이미 존재하는 아이템이 있으면 true, 없으면 false + // 시간복잡도 : O(n), 공간복잡도 : O(n) + fun containsDuplicate(nums: IntArray): Boolean { + val set = HashSet() + for (num in nums) { + if (set.contains(num)) { + return true + } + set.add(num) + } + return false + } +} \ No newline at end of file From 7ff3409940f9e51c218bd9c0a66f94e3ce29dcc0 Mon Sep 17 00:00:00 2001 From: ace kim Date: Tue, 3 Mar 2026 00:16:26 +0800 Subject: [PATCH 2/5] add new line --- contains-duplicate/acious.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contains-duplicate/acious.kt b/contains-duplicate/acious.kt index b22f8dad06..d2f96c9238 100644 --- a/contains-duplicate/acious.kt +++ b/contains-duplicate/acious.kt @@ -13,4 +13,4 @@ class Solution { } return false } -} \ No newline at end of file +} From 8c7805e9ea2802e66a2eb0bc882aed7c3506e634 Mon Sep 17 00:00:00 2001 From: ace kim Date: Tue, 3 Mar 2026 01:44:31 +0800 Subject: [PATCH 3/5] Solved 219 - Two sum --- two-sum/acious.kt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 two-sum/acious.kt diff --git a/two-sum/acious.kt b/two-sum/acious.kt new file mode 100644 index 0000000000..7fa4ced659 --- /dev/null +++ b/two-sum/acious.kt @@ -0,0 +1,25 @@ +class Solution { + // nums의 모든 숫자를 Map에 저장. key는 nums의 숫자, value는 해당 숫자의 인덱스 + // target의 숫자가 동일한 숫자가 더해져야 하는 케이스 (예: target = 4, nums = [2, 2])를 위해 value는 List로 저장 + // 시간복잡도: O(n), 공간복잡도: O(n) + fun twoSum(nums: IntArray, target: Int): IntArray { + val map = mutableMapOf>() + for (index in nums.indices) { // nums.indices는 nums의 인덱스 범위를 반환 + val list = map.getOrDefault(nums[index], mutableListOf()) + list.add(index) + map[nums[index]] = list + } + for (index in nums.indices) { + val complement = target - nums[index] + val complementIndices = map[complement] + if (complementIndices != null) { + for (complementIndex in complementIndices) { + if (complementIndex != index) { + return intArrayOf(index, complementIndex) + } + } + } + } + throw IllegalArgumentException("No two sum solution") + } +} \ No newline at end of file From f57e5036ef94fe32703d2f7050fc6f9a1dce47f0 Mon Sep 17 00:00:00 2001 From: ace kim Date: Tue, 3 Mar 2026 01:45:12 +0800 Subject: [PATCH 4/5] add new line --- two-sum/acious.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/acious.kt b/two-sum/acious.kt index 7fa4ced659..89381609b6 100644 --- a/two-sum/acious.kt +++ b/two-sum/acious.kt @@ -22,4 +22,4 @@ class Solution { } throw IllegalArgumentException("No two sum solution") } -} \ No newline at end of file +} From bb37caa3fcae7c9f6cdae849cb49de3a3140eaf4 Mon Sep 17 00:00:00 2001 From: ace kim Date: Tue, 3 Mar 2026 01:48:40 +0800 Subject: [PATCH 5/5] add improvement point --- two-sum/acious.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/two-sum/acious.kt b/two-sum/acious.kt index 89381609b6..cead1e7d96 100644 --- a/two-sum/acious.kt +++ b/two-sum/acious.kt @@ -2,6 +2,7 @@ class Solution { // nums의 모든 숫자를 Map에 저장. key는 nums의 숫자, value는 해당 숫자의 인덱스 // target의 숫자가 동일한 숫자가 더해져야 하는 케이스 (예: target = 4, nums = [2, 2])를 위해 value는 List로 저장 // 시간복잡도: O(n), 공간복잡도: O(n) + // improvement point : 한번의 루프를 순회하는 것으로도 문제를 해결할 수 있음. fun twoSum(nums: IntArray, target: Int): IntArray { val map = mutableMapOf>() for (index in nums.indices) { // nums.indices는 nums의 인덱스 범위를 반환