From 9c9fb847342084ff77335433d76e5d32f81817f3 Mon Sep 17 00:00:00 2001 From: Yeryeong Kang Date: Sat, 14 Nov 2026 15:13:43 +0900 Subject: [PATCH 1/5] contains duplicate solution --- contains-duplicate/ehlung.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 contains-duplicate/ehlung.py diff --git a/contains-duplicate/ehlung.py b/contains-duplicate/ehlung.py new file mode 100644 index 0000000000..79c6014c00 --- /dev/null +++ b/contains-duplicate/ehlung.py @@ -0,0 +1,15 @@ +""" +n = nums의 길이 +시간 복잡도: O(n) - 각 숫자를 한 번씩 확인 (set 조회/추가는 O(1)) +공간 복잡도: O(n) - 지금까지 본 숫자들을 담는 set +""" + + +class Solution: + def containsDuplicate(self, nums: list[int]) -> bool: + seen = set() + for num in nums: + if num in seen: + return True + seen.add(num) + return False From 28b7ad5fbd1610a9d1543be65b809abb6742b9f2 Mon Sep 17 00:00:00 2001 From: Yeryeong Kang Date: Sat, 14 Nov 2026 15:13:43 +0900 Subject: [PATCH 2/5] two sum solution --- two-sum/ehlung.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 two-sum/ehlung.py diff --git a/two-sum/ehlung.py b/two-sum/ehlung.py new file mode 100644 index 0000000000..5ef5f17980 --- /dev/null +++ b/two-sum/ehlung.py @@ -0,0 +1,16 @@ +""" +n = nums의 길이 +시간 복잡도: O(n) - 각 숫자를 한 번씩 확인 (딕셔너리 조회/저장은 O(1)) +공간 복잡도: O(n) - 숫자와 인덱스를 담는 딕셔너리 +""" + + +class Solution: + def twoSum(self, nums: list[int], target: int) -> list[int]: + index_of = {} + for i, num in enumerate(nums): + need = target - num + if need in index_of: + return [index_of[need], i] + index_of[num] = i + return [] From d3c606746f9facfec1400993f89ea752d4fa7269 Mon Sep 17 00:00:00 2001 From: Yeryeong Kang Date: Sat, 14 Nov 2026 15:13:43 +0900 Subject: [PATCH 3/5] top k frequent elements solution --- top-k-frequent-elements/ehlung.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 top-k-frequent-elements/ehlung.py diff --git a/top-k-frequent-elements/ehlung.py b/top-k-frequent-elements/ehlung.py new file mode 100644 index 0000000000..91df56fba7 --- /dev/null +++ b/top-k-frequent-elements/ehlung.py @@ -0,0 +1,15 @@ +""" +n = nums의 길이, m = 서로 다른 숫자의 개수 +시간 복잡도: O(n + m log m) - 빈도 세기 O(n) + 서로 다른 숫자 m개를 빈도순 정렬 O(m log m) +공간 복잡도: O(m) - 숫자별 빈도를 담는 딕셔너리와 정렬 결과 +""" + + +class Solution: + def topKFrequent(self, nums: list[int], k: int) -> list[int]: + count = {} + for num in nums: + count[num] = count.get(num, 0) + 1 + + sorted_nums = sorted(count, key=lambda num: count[num], reverse=True) + return sorted_nums[:k] From 3ad36de49443a282dfc9db16299aac5a6f3375ba Mon Sep 17 00:00:00 2001 From: Yeryeong Kang Date: Sat, 14 Nov 2026 15:13:43 +0900 Subject: [PATCH 4/5] longest consecutive sequence solution --- longest-consecutive-sequence/ehlung.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 longest-consecutive-sequence/ehlung.py diff --git a/longest-consecutive-sequence/ehlung.py b/longest-consecutive-sequence/ehlung.py new file mode 100644 index 0000000000..1bf029ec2f --- /dev/null +++ b/longest-consecutive-sequence/ehlung.py @@ -0,0 +1,21 @@ +""" +n = nums의 길이 +시간 복잡도: O(n) - 시작점에서만 세어 나가서 각 숫자는 최대 두 번만 확인 +공간 복잡도: O(n) - 모든 숫자를 담는 set +""" + + +class Solution: + def longestConsecutive(self, nums: list[int]) -> int: + num_set = set(nums) + longest = 0 + + for num in num_set: + # 수열의 시작점에서만 길이를 센다 + if num - 1 not in num_set: + length = 1 + while num + length in num_set: + length += 1 + longest = max(longest, length) + + return longest From 6b1c9be0d75730209bd7321576558de826223d0b Mon Sep 17 00:00:00 2001 From: Yeryeong Kang Date: Sat, 14 Nov 2026 15:13:43 +0900 Subject: [PATCH 5/5] house robber solution --- house-robber/ehlung.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 house-robber/ehlung.py diff --git a/house-robber/ehlung.py b/house-robber/ehlung.py new file mode 100644 index 0000000000..ed30edfa51 --- /dev/null +++ b/house-robber/ehlung.py @@ -0,0 +1,14 @@ +""" +n = nums의 길이 +시간 복잡도: O(n) - 각 집을 한 번씩 확인 +공간 복잡도: O(1) - 배열 없이 변수 두 개만 사용 +""" + + +class Solution: + def rob(self, nums: list[int]) -> int: + # prev2: 두 집 전까지의 최대 금액, prev1: 바로 전 집까지의 최대 금액 + prev2, prev1 = 0, 0 + for money in nums: + prev2, prev1 = prev1, max(prev2 + money, prev1) + return prev1