From 8a353fcd53d935f7da32008e6c0ab9db58e89802 Mon Sep 17 00:00:00 2001 From: jeongyunjae Date: Sun, 20 Jul 2025 19:36:57 +0900 Subject: [PATCH 1/7] [main] contains-duplicate solution --- contains-duplicate/jeongyunjae.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 contains-duplicate/jeongyunjae.py diff --git a/contains-duplicate/jeongyunjae.py b/contains-duplicate/jeongyunjae.py new file mode 100644 index 000000000..2d99650be --- /dev/null +++ b/contains-duplicate/jeongyunjae.py @@ -0,0 +1,3 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + return len(list(set(nums))) != len(nums) From 262b903c4379a1204174f8735e2f433937e0194d Mon Sep 17 00:00:00 2001 From: jeongyunjae Date: Sun, 20 Jul 2025 19:37:38 +0900 Subject: [PATCH 2/7] [main] two sum solution --- two-sum/jeongyunjae.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 two-sum/jeongyunjae.py diff --git a/two-sum/jeongyunjae.py b/two-sum/jeongyunjae.py new file mode 100644 index 000000000..f8480c75e --- /dev/null +++ b/two-sum/jeongyunjae.py @@ -0,0 +1,11 @@ +class Solution: + + def twoSum(self, nums: List[int], target: int) -> List[int]: + my_dict = {} + + for i in range(len(nums)): + remaining = target - nums[i] + if remaining not in my_dict: + my_dict[nums[i]] = i + else: + return [my_dict[remaining], i] From 2e824d594a1afe37ac5c057c43ca234f501a8b56 Mon Sep 17 00:00:00 2001 From: jeongyunjae Date: Sat, 26 Jul 2025 14:45:23 +0900 Subject: [PATCH 3/7] [main] two-sum review --- two-sum/jeongyunjae.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/two-sum/jeongyunjae.py b/two-sum/jeongyunjae.py index f8480c75e..1b0925496 100644 --- a/two-sum/jeongyunjae.py +++ b/two-sum/jeongyunjae.py @@ -3,9 +3,9 @@ class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: my_dict = {} - for i in range(len(nums)): - remaining = target - nums[i] + for i, data in enumerate(nums): + remaining = target - data if remaining not in my_dict: - my_dict[nums[i]] = i + my_dict[data] = i else: return [my_dict[remaining], i] From dc54f47e333b537afeabb1113ae56b8225177af2 Mon Sep 17 00:00:00 2001 From: jeongyunjae Date: Sat, 26 Jul 2025 14:46:03 +0900 Subject: [PATCH 4/7] [main] top-k-frequent-elements solution --- top-k-frequent-elements/jeongyunjae.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 top-k-frequent-elements/jeongyunjae.py diff --git a/top-k-frequent-elements/jeongyunjae.py b/top-k-frequent-elements/jeongyunjae.py new file mode 100644 index 000000000..d7cd7ffdc --- /dev/null +++ b/top-k-frequent-elements/jeongyunjae.py @@ -0,0 +1,25 @@ +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + my_dict = {} + result = [] + temp_list = [] + + # 딕셔너리 생성 + for data in nums: + if data not in my_dict.keys(): + my_dict[data] = 0 + my_dict[data] = my_dict[data] + 1 + + # 딕셔너리를 리스트로 변환 + for data in my_dict.keys(): + temp_list.append([data, my_dict[data]]) + + # 빈도수를 기준으로 정렬 + temp_list.sort(key=lambda a: a[1],reverse=True) + + # 상위 k개 요소 추출 + for i in range(k): + result.append(temp_list[i][0]) + + return result + \ No newline at end of file From 190b0112d3d012d4cb0ccc50a3ae5abcf4309275 Mon Sep 17 00:00:00 2001 From: jeongyunjae Date: Sat, 26 Jul 2025 14:53:12 +0900 Subject: [PATCH 5/7] [main] fix: lint --- top-k-frequent-elements/jeongyunjae.py | 1 - 1 file changed, 1 deletion(-) diff --git a/top-k-frequent-elements/jeongyunjae.py b/top-k-frequent-elements/jeongyunjae.py index d7cd7ffdc..c1869f7e6 100644 --- a/top-k-frequent-elements/jeongyunjae.py +++ b/top-k-frequent-elements/jeongyunjae.py @@ -22,4 +22,3 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]: result.append(temp_list[i][0]) return result - \ No newline at end of file From a9593e822549e0106c3ab9a7b7226c65745e7c61 Mon Sep 17 00:00:00 2001 From: jeongyunjae Date: Sat, 26 Jul 2025 16:46:15 +0900 Subject: [PATCH 6/7] [main] longest-consecutive-sequence solution --- longest-consecutive-sequence/jeongyunjae.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 longest-consecutive-sequence/jeongyunjae.py diff --git a/longest-consecutive-sequence/jeongyunjae.py b/longest-consecutive-sequence/jeongyunjae.py new file mode 100644 index 000000000..95d914dce --- /dev/null +++ b/longest-consecutive-sequence/jeongyunjae.py @@ -0,0 +1,16 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + if len(nums) <= 1: + return len(nums) + + result = [1] * len(nums) + + # 중복 제거 후 정렬 + nums = sorted(list(set(nums))) + + # 연속된 숫자 찾기 + for i in range(1, len(nums)): + if nums[i] - 1 == nums[i-1]: + result[i] = result[i-1] + 1 + + return max(result) From 3c2f0b0919775deee17fcd9c6a75cbe88a497b86 Mon Sep 17 00:00:00 2001 From: jeongyunjae Date: Sat, 26 Jul 2025 17:22:48 +0900 Subject: [PATCH 7/7] [main] house-robber solution --- house-robber/jeongyunjae.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 house-robber/jeongyunjae.py diff --git a/house-robber/jeongyunjae.py b/house-robber/jeongyunjae.py new file mode 100644 index 000000000..612180e32 --- /dev/null +++ b/house-robber/jeongyunjae.py @@ -0,0 +1,18 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + result = list(nums) + + for i, data in enumerate(result): + if i <= 1: + continue + + stolen_money = result[i] + before_house_money = result[i-1] + + for j in range(i-1): + if result[i] + result[j] > stolen_money: + stolen_money = result[i] + result[j] + + result[i] = max(before_house_money, stolen_money) + + return max(result)