From e890414c9b4bfd92caad5add935513fb39ad2130 Mon Sep 17 00:00:00 2001 From: dohee Date: Tue, 3 Mar 2026 10:36:37 -0500 Subject: [PATCH 1/3] 217. Contains Duplicate Solution --- contains-duplicate/doh6077.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/contains-duplicate/doh6077.py b/contains-duplicate/doh6077.py index bc14e47f24..f755a81036 100644 --- a/contains-duplicate/doh6077.py +++ b/contains-duplicate/doh6077.py @@ -1,10 +1,8 @@ +# https://leetcode.com/problems/contains-duplicate/description/ -# set에 저장하면서 중복 여부 확인하기 class Solution: - def containsDuplicate(self, nums: list[int]) -> bool: - hashset = set() - for i in nums: - if i in hashset: - return True - hashset.add(i) - return False + def containsDuplicate(self, nums: List[int]) -> bool: + # Create a set to store unique numbers from nums + nums_set = set(nums) + return len(nums_set) != len(nums) + \ No newline at end of file From 03641f93aae037e5a23398cdd76df82bfc54954e Mon Sep 17 00:00:00 2001 From: dohee Date: Tue, 3 Mar 2026 10:43:08 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contains-duplicate/doh6077.py | 1 - 1 file changed, 1 deletion(-) diff --git a/contains-duplicate/doh6077.py b/contains-duplicate/doh6077.py index f755a81036..11a03c3ca6 100644 --- a/contains-duplicate/doh6077.py +++ b/contains-duplicate/doh6077.py @@ -5,4 +5,3 @@ def containsDuplicate(self, nums: List[int]) -> bool: # Create a set to store unique numbers from nums nums_set = set(nums) return len(nums_set) != len(nums) - \ No newline at end of file From 7755c5d899e67dab9b29379e90dd86b486ddf2b6 Mon Sep 17 00:00:00 2001 From: dohee Date: Tue, 3 Mar 2026 11:20:36 -0500 Subject: [PATCH 3/3] Two Sum solution --- two-sum/doh6077.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/two-sum/doh6077.py b/two-sum/doh6077.py index 2054ef0def..d8c8a3683a 100644 --- a/two-sum/doh6077.py +++ b/two-sum/doh6077.py @@ -1,8 +1,24 @@ +# 6기 +# class Solution: +# def twoSum(self, nums: list[int], target: int) -> list[int]: +# prevMap = {} # val : index +# for i, n in enumerate(nums): +# diff = target - n +# if diff in prevMap: +# return [prevMap[diff], i] +# prevMap[n] = i + +# 7기 +# https://leetcode.com/problems/two-sum/description/ class Solution: - def twoSum(self, nums: list[int], target: int) -> list[int]: - prevMap = {} # val : index - for i, n in enumerate(nums): - diff = target - n - if diff in prevMap: - return [prevMap[diff], i] - prevMap[n] = i + def twoSum(self, nums: List[int], target: int) -> List[int]: + # use Hash map to save num and index + nums_hm = {} + + for i, num in enumerate(nums): + find_val = target - num + + if find_val in nums_hm: + return [nums_hm[find_val], i] + + nums_hm[num] = i