From eec10a28411b5aec6f78e5d2d06f75d06834a992 Mon Sep 17 00:00:00 2001 From: sojae Date: Fri, 14 Nov 2025 10:19:23 +0900 Subject: [PATCH 1/6] feat:contains-duplicate --- contains-duplicate/socow.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 contains-duplicate/socow.py diff --git a/contains-duplicate/socow.py b/contains-duplicate/socow.py new file mode 100644 index 0000000000..3039914a78 --- /dev/null +++ b/contains-duplicate/socow.py @@ -0,0 +1,35 @@ +# 문제 내용 +# 배열 nums에 같은 값이 2번 이상 등장하면 True, 아니면 False. +# 가장 실전적인 방법: 해시셋(Set)으로 한 번씩 보며 등장 여부 체크 +# → 이미 본 값이면 바로 True 반환(조기 종료). + +# 문제 풀이 설명 +# set은 중복을 허용하지 않는 집합이다 +# 리스트르 set으로 바꾸면 중복이 제거된다 +# 따라서 길이를 비교하면 중복 여부를 알 수 있다 + +# 중복이 있는 경우 +# >>> nums = [1,2,3,2] +# >>> len(nums) +# 4 +# >>> set(nums) +# {1, 2, 3} +# >>> len(set(nums)) +# 3 +# >>> len(nums) != len(set(nums)) +# True + +# 중복이 없는 경우 +# >>> nums = [1,2,3] +# >>> len(nums) +# 3 +# >>> set(nums) +# {1, 2, 3} +# >>> len(set(nums)) +# 3 +# >>> len(nums) != len(set(nums)) +# False +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + return len(nums) != len(set(nums)) + From d3ce1d489ac3c168d14c481532a5e24680166845 Mon Sep 17 00:00:00 2001 From: sojae Date: Fri, 14 Nov 2025 10:21:28 +0900 Subject: [PATCH 2/6] feat:two-sum --- two-sum/socow.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 two-sum/socow.py diff --git a/two-sum/socow.py b/two-sum/socow.py new file mode 100644 index 0000000000..bcf7f082a8 --- /dev/null +++ b/two-sum/socow.py @@ -0,0 +1,16 @@ +# 1. 일단 딕셔너리(num_map)를 만들어서 숫자랑 인덱스를 저장한다. +# 2. 현재 숫자와 target을 뺀 결과(보충값, complement)를 계산한다. +# 3. 그 complement가 이미 딕셔너리에 있다면? +# → 그 숫자와 현재 숫자가 합쳐서 target이 된다는 뜻! +# 4. 없다면 현재 숫자를 딕셔너리에 저장해서 다음에 대비한다. +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + num_map = {} + + for i, num in enumerate(nums): + complement = target - num + + if complement in num_map: + return [num_map[complement], i] + + num_map[num] = i \ No newline at end of file From 6671dcf743e5e31d8ccd4606e6c175520a4d955e Mon Sep 17 00:00:00 2001 From: sojae Date: Fri, 14 Nov 2025 10:35:52 +0900 Subject: [PATCH 3/6] =?UTF-8?q?fix:=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/socow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/two-sum/socow.py b/two-sum/socow.py index bcf7f082a8..f30260214a 100644 --- a/two-sum/socow.py +++ b/two-sum/socow.py @@ -13,4 +13,5 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if complement in num_map: return [num_map[complement], i] - num_map[num] = i \ No newline at end of file + num_map[num] = i + \ No newline at end of file From 2e0702f6c846e985945ce83bd91fdce2a569b99a Mon Sep 17 00:00:00 2001 From: sojae Date: Fri, 14 Nov 2025 10:40:11 +0900 Subject: [PATCH 4/6] =?UTF-8?q?fix:=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/socow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/socow.py b/two-sum/socow.py index f30260214a..ee3491b43d 100644 --- a/two-sum/socow.py +++ b/two-sum/socow.py @@ -3,6 +3,7 @@ # 3. 그 complement가 이미 딕셔너리에 있다면? # → 그 숫자와 현재 숫자가 합쳐서 target이 된다는 뜻! # 4. 없다면 현재 숫자를 딕셔너리에 저장해서 다음에 대비한다. + class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: num_map = {} @@ -12,6 +13,5 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if complement in num_map: return [num_map[complement], i] - num_map[num] = i \ No newline at end of file From 0c98424e8ccc070d7b77b5d400bec35b46e3e1ea Mon Sep 17 00:00:00 2001 From: sojae Date: Fri, 14 Nov 2025 10:46:46 +0900 Subject: [PATCH 5/6] =?UTF-8?q?fix:=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/socow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/two-sum/socow.py b/two-sum/socow.py index ee3491b43d..f8d7c7884c 100644 --- a/two-sum/socow.py +++ b/two-sum/socow.py @@ -14,4 +14,5 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if complement in num_map: return [num_map[complement], i] num_map[num] = i - \ No newline at end of file + return [] + \ No newline at end of file From d7db6558fe90738a2eedd202c49dab376400e9e5 Mon Sep 17 00:00:00 2001 From: sojae Date: Fri, 14 Nov 2025 10:51:51 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix:=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/socow.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/two-sum/socow.py b/two-sum/socow.py index f8d7c7884c..c5fb6dcf3e 100644 --- a/two-sum/socow.py +++ b/two-sum/socow.py @@ -14,5 +14,3 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if complement in num_map: return [num_map[complement], i] num_map[num] = i - return [] - \ No newline at end of file