From b6e35e7b3443d60e415e1f8725dc12e6f45986e6 Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Fri, 26 Jun 2026 01:17:37 +0100 Subject: [PATCH 1/4] Implement containsDuplicate method in Solution class --- contains-duplicate/Chanz82.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 contains-duplicate/Chanz82.py diff --git a/contains-duplicate/Chanz82.py b/contains-duplicate/Chanz82.py new file mode 100644 index 0000000000..55fcc66236 --- /dev/null +++ b/contains-duplicate/Chanz82.py @@ -0,0 +1,10 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + hashmap = dict() + sorted(nums) + for num in nums: + if hashmap.get(num, False) == True: + return True + else : + hashmap[num] = True + return False From e026ddde21f265c9f0363031e4a15bb5cb22c41f Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Fri, 26 Jun 2026 23:29:01 +0100 Subject: [PATCH 2/4] Add twoSum method in Solution class Implement twoSum method to find indices of two numbers that add up to target. --- two-sum/Chanz.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 two-sum/Chanz.py diff --git a/two-sum/Chanz.py b/two-sum/Chanz.py new file mode 100644 index 0000000000..5c41451095 --- /dev/null +++ b/two-sum/Chanz.py @@ -0,0 +1,20 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + + ## 공간 복잡도 : O(n) + ## - n 개수 만큼의 hashmap 공간만을 사용하므로 공간복잡도가 O(n)이라고 생각합니다. + + ## 시간 복잡도 : O(n) + ## - hashmap에 값과 idx를 매칭하는 작업을 n번 수행합니다. + ## - 이후 다시 nums를 순회하면서 target이 되는 짝을 찾습니다. + ## - 따라서 Worst N번 이므로, 2n = O(n)이라고 생각합니다. + + hashmap = dict() + for idx, num in enumerate(nums): + hashmap[num] = idx + + for idx, num in enumerate(nums): + matched_num_idx = hashmap.get(target-num) + if matched_num_idx and matched_num_idx != idx: + return [idx, matched_num_idx] + From e8339c9b9f962f89ab0459ec6ebdefd96a474e2b Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Fri, 26 Jun 2026 23:30:47 +0100 Subject: [PATCH 3/4] Rename Chanz.py to Chanz82.py --- two-sum/{Chanz.py => Chanz82.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename two-sum/{Chanz.py => Chanz82.py} (100%) diff --git a/two-sum/Chanz.py b/two-sum/Chanz82.py similarity index 100% rename from two-sum/Chanz.py rename to two-sum/Chanz82.py From 40cb681a27a3b615df351f65a89f2f2e0c58840e Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Fri, 26 Jun 2026 23:46:22 +0100 Subject: [PATCH 4/4] Optimize two-sum algorithm with single loop Refactor two-sum solution to use a single loop for finding matches. --- two-sum/Chanz82.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/two-sum/Chanz82.py b/two-sum/Chanz82.py index 5c41451095..55ef11f80e 100644 --- a/two-sum/Chanz82.py +++ b/two-sum/Chanz82.py @@ -10,11 +10,11 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: ## - 따라서 Worst N번 이므로, 2n = O(n)이라고 생각합니다. hashmap = dict() + for idx, num in enumerate(nums): - hashmap[num] = idx - - for idx, num in enumerate(nums): - matched_num_idx = hashmap.get(target-num) - if matched_num_idx and matched_num_idx != idx: - return [idx, matched_num_idx] + possible_match = target - num + if possible_match in hashmap: + return [idx, hashmap[possible_match]] + else: + hashmap[num] = idx