From f7540e3bab53f79c50c70a57f07ebcfd99946f83 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 13 Nov 2025 00:20:33 -0500 Subject: [PATCH 1/4] two sum solution --- two-sum/doh6077.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 two-sum/doh6077.py diff --git a/two-sum/doh6077.py b/two-sum/doh6077.py new file mode 100644 index 0000000000..333302d8ec --- /dev/null +++ b/two-sum/doh6077.py @@ -0,0 +1,8 @@ +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 \ No newline at end of file From 3e887656b907eb036600b54d9c739206f9b785c9 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 13 Nov 2025 00:32:31 -0500 Subject: [PATCH 2/4] two sum solution --- two-sum/doh6077.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/two-sum/doh6077.py b/two-sum/doh6077.py index 333302d8ec..ddc6072e74 100644 --- a/two-sum/doh6077.py +++ b/two-sum/doh6077.py @@ -5,4 +5,5 @@ def twoSum(self, nums: list[int], target: int) -> list[int]: diff = target - n if diff in prevMap: return [prevMap[diff], i] - prevMap[n] = i \ No newline at end of file + prevMap[n] = i + \ No newline at end of file From 3d40dbc43ad0e94af72923e2af6ec2e0b586ef7b Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 14 Nov 2025 11:55:35 -0500 Subject: [PATCH 3/4] contains duplicate solution --- contains-duplicate/doh6077.py | 10 ++++++++++ two-sum/doh6077.py | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 contains-duplicate/doh6077.py diff --git a/contains-duplicate/doh6077.py b/contains-duplicate/doh6077.py new file mode 100644 index 0000000000..bc14e47f24 --- /dev/null +++ b/contains-duplicate/doh6077.py @@ -0,0 +1,10 @@ + +# 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 diff --git a/two-sum/doh6077.py b/two-sum/doh6077.py index ddc6072e74..2054ef0def 100644 --- a/two-sum/doh6077.py +++ b/two-sum/doh6077.py @@ -6,4 +6,3 @@ def twoSum(self, nums: list[int], target: int) -> list[int]: if diff in prevMap: return [prevMap[diff], i] prevMap[n] = i - \ No newline at end of file From 0c700f00c14091d1762446b86bbb1515a891dbf7 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 14 Nov 2025 18:09:06 -0500 Subject: [PATCH 4/4] Longest Consecutive Sequence Solution --- longest-consecutive-sequence/doh6077.py | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 longest-consecutive-sequence/doh6077.py diff --git a/longest-consecutive-sequence/doh6077.py b/longest-consecutive-sequence/doh6077.py new file mode 100644 index 0000000000..75df1d3fe0 --- /dev/null +++ b/longest-consecutive-sequence/doh6077.py @@ -0,0 +1,34 @@ +# 배열을 정렬하고 포인터를 두개 사용 +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + if not nums: + return 0 + + # sort the given list + sorted_nums = sorted(nums) + + longest = 1 + curr = 1 + + l, r = 0, 1 + + while r < len(sorted_nums): + # case 1: exactly consecutive (x, x+1) + if sorted_nums[r] == sorted_nums[l] + 1: + curr += 1 + longest = max(longest, curr) + l += 1 + r += 1 + + # case 2: duplicate (x, x) → ignore, move right pointer + elif sorted_nums[r] == sorted_nums[l]: + l += 1 + r += 1 + + # case 3: gap + else: + curr = 1 + l = r + r += 1 + + return longest