From 254e4c72259d783a8351898074ca487b99e12e55 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Tue, 3 Mar 2026 00:49:52 +0900 Subject: [PATCH 1/9] two sum solution --- two-sum/hyeri0903.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 two-sum/hyeri0903.py diff --git a/two-sum/hyeri0903.py b/two-sum/hyeri0903.py new file mode 100644 index 0000000000..4f84b60079 --- /dev/null +++ b/two-sum/hyeri0903.py @@ -0,0 +1,7 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + + for i in range(len(nums)): + for j in range(i+1, len(nums)): + if nums[i] + nums[j] == target: + return [i, j] \ No newline at end of file From 03076320757dd8baf7724eab27c3a024955a10a9 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Tue, 3 Mar 2026 00:56:16 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=EA=B0=9C=ED=96=89=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/hyeri0903.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/two-sum/hyeri0903.py b/two-sum/hyeri0903.py index 4f84b60079..2e82f79299 100644 --- a/two-sum/hyeri0903.py +++ b/two-sum/hyeri0903.py @@ -4,4 +4,5 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i] + nums[j] == target: - return [i, j] \ No newline at end of file + return [i, j] + \ No newline at end of file From f551b03453c5242878016d443d935b886e51251b Mon Sep 17 00:00:00 2001 From: hyerijung Date: Tue, 3 Mar 2026 01:04:41 +0900 Subject: [PATCH 3/9] add new line --- two-sum/hyeri0903.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/hyeri0903.py b/two-sum/hyeri0903.py index 2e82f79299..f39a67cd06 100644 --- a/two-sum/hyeri0903.py +++ b/two-sum/hyeri0903.py @@ -5,4 +5,4 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: for j in range(i+1, len(nums)): if nums[i] + nums[j] == target: return [i, j] - \ No newline at end of file + From 12e62d0ee22b8774aa1f3112ab6c2b86f6b5c708 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Wed, 4 Mar 2026 15:52:53 +0900 Subject: [PATCH 4/9] contain duplicate solution --- contains-duplicate/hyeri0903.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 contains-duplicate/hyeri0903.py diff --git a/contains-duplicate/hyeri0903.py b/contains-duplicate/hyeri0903.py new file mode 100644 index 0000000000..658410fef9 --- /dev/null +++ b/contains-duplicate/hyeri0903.py @@ -0,0 +1,13 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + ans = False + dic = dict() + + for n in nums: + if n in dic: + return True + else: + dic[n] = 1 + return ans + + From 8fa2c602c4e1b3572a013fd8cc2b08fad627f46d Mon Sep 17 00:00:00 2001 From: hyerijung Date: Wed, 4 Mar 2026 16:03:00 +0900 Subject: [PATCH 5/9] top-k-frequent-elements solution --- top-k-frequent-elements/hyeri0903.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 top-k-frequent-elements/hyeri0903.py diff --git a/top-k-frequent-elements/hyeri0903.py b/top-k-frequent-elements/hyeri0903.py new file mode 100644 index 0000000000..709dab054f --- /dev/null +++ b/top-k-frequent-elements/hyeri0903.py @@ -0,0 +1,12 @@ +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + table = {} + for n in nums: + if n in table: + table[n] += 1 + else: + table[n] = 1 + sorted_table = sorted(table.items(), key=lambda x:x[1], reverse = True) + + return [ key for key, freq in sorted_table[:k]] + \ No newline at end of file From 7f99b920a9b7ed876e2d996bf81eb8616b57f354 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Wed, 4 Mar 2026 16:11:12 +0900 Subject: [PATCH 6/9] top-l-frequent-elements solution2 --- top-k-frequent-elements/hyeri0903.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/top-k-frequent-elements/hyeri0903.py b/top-k-frequent-elements/hyeri0903.py index 709dab054f..9ea774985c 100644 --- a/top-k-frequent-elements/hyeri0903.py +++ b/top-k-frequent-elements/hyeri0903.py @@ -1,3 +1,5 @@ +import heapq + class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: table = {} @@ -6,7 +8,17 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]: table[n] += 1 else: table[n] = 1 - sorted_table = sorted(table.items(), key=lambda x:x[1], reverse = True) - - return [ key for key, freq in sorted_table[:k]] - \ No newline at end of file + #sol 1) sorting 사용한 case + # sorted_table = sorted(table.items(), key=lambda x:x[1], reverse = True) + # return [ key for key, freq in sorted_table[:k]] + + #sol 2) min heap 사용한 case + #convert the frequencies to negative values so it return first + heap = [(-freq, key) for key, freq in table.items()] + heapq.heapify(heap) + + res = [] + for _ in range(k): + freq, key = heapq.heappop(heap) + res.append(key) + return res From 8c2adbcc50d11828b5d3904b1aa137995a4d01c7 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Wed, 4 Mar 2026 16:19:53 +0900 Subject: [PATCH 7/9] longest-consecutive-sequence solution --- longest-consecutive-sequence/hyeri0903.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 longest-consecutive-sequence/hyeri0903.py diff --git a/longest-consecutive-sequence/hyeri0903.py b/longest-consecutive-sequence/hyeri0903.py new file mode 100644 index 0000000000..1f3029e104 --- /dev/null +++ b/longest-consecutive-sequence/hyeri0903.py @@ -0,0 +1,17 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + if len(nums) <= 0: + return 0 + res , cnt = 1, 1 + sorted_nums = list(set(nums)) + sorted_nums.sort() + print(sorted_nums) + + for i in range(len(sorted_nums)-1): + if sorted_nums[i+1] - sorted_nums[i] == 1: + cnt += 1 + else: + cnt = 1 + res = max(res, cnt) + return res + \ No newline at end of file From 6a0c851c368d2f44d91c78ed7fca95ba7e77fc5d Mon Sep 17 00:00:00 2001 From: hyerijung Date: Wed, 4 Mar 2026 16:30:28 +0900 Subject: [PATCH 8/9] longestConsecutive solution2 --- longest-consecutive-sequence/hyeri0903.py | 39 +++++++++++++++++------ 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/longest-consecutive-sequence/hyeri0903.py b/longest-consecutive-sequence/hyeri0903.py index 1f3029e104..82b6c53792 100644 --- a/longest-consecutive-sequence/hyeri0903.py +++ b/longest-consecutive-sequence/hyeri0903.py @@ -2,16 +2,35 @@ class Solution: def longestConsecutive(self, nums: List[int]) -> int: if len(nums) <= 0: return 0 - res , cnt = 1, 1 - sorted_nums = list(set(nums)) - sorted_nums.sort() - print(sorted_nums) - for i in range(len(sorted_nums)-1): - if sorted_nums[i+1] - sorted_nums[i] == 1: - cnt += 1 + res = 0 + length = 1 + nums.sort() + + for i in range(len(nums)-1): + if nums[i] == nums[i+1]: + continue + if nums[i] + 1 == nums[i+1]: + length += 1 else: - cnt = 1 - res = max(res, cnt) + res = max(res, length) + length = 1 + + res = max(res, length) return res - \ No newline at end of file + + #set을 사용한 풀이 + # if len(nums) <= 0: + # return 0 + # res, cnt = 1, 1 + # sorted_nums = list(set(nums)) + # sorted_nums.sort() + # print(sorted_nums) + + # for i in range(len(sorted_nums) - 1): + # if sorted_nums[i + 1] - sorted_nums[i] == 1: + # cnt += 1 + # else: + # cnt = 1 + # res = max(res, cnt) + # return res From 1f51b199a3b7e17a80a9b5fe37ecbf77ed7aa1a9 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Thu, 5 Mar 2026 21:55:44 +0900 Subject: [PATCH 9/9] house robber solution --- house-robber/hyeri0903.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 house-robber/hyeri0903.py diff --git a/house-robber/hyeri0903.py b/house-robber/hyeri0903.py new file mode 100644 index 0000000000..069fdad948 --- /dev/null +++ b/house-robber/hyeri0903.py @@ -0,0 +1,14 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + dp = {} + dp[0] = nums[0] + if len(nums) >= 2: + dp[1] = max(nums[0], nums[1]) + else: + return nums[0] + + for i in range(2, len(nums)): + dp[i] = max(dp[i-1], dp[i-2] + nums[i]) + + res = list(dp.values())[-1] + return res