From 106d6dec853c87a9157041bee9d825d75a6c4782 Mon Sep 17 00:00:00 2001 From: mrlee7 Date: Fri, 6 Mar 2026 23:12:53 +0900 Subject: [PATCH 1/4] two sum solution --- two-sum/mrlee7.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 two-sum/mrlee7.py diff --git a/two-sum/mrlee7.py b/two-sum/mrlee7.py new file mode 100644 index 0000000000..7d792dfed0 --- /dev/null +++ b/two-sum/mrlee7.py @@ -0,0 +1,10 @@ +from typing import List + + +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + + for i in range(0, len(nums) - 1): + for j in range(i + 1, len(nums)): + if (target - nums[i]) == nums[j]: + return [i, j] \ No newline at end of file From a9db90e7999e43bba2ce8f4de172b639df9d03c1 Mon Sep 17 00:00:00 2001 From: mrlee7 Date: Fri, 6 Mar 2026 23:22:59 +0900 Subject: [PATCH 2/4] formatting two sum code --- two-sum/mrlee7.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/mrlee7.py b/two-sum/mrlee7.py index 7d792dfed0..8ada5a68f0 100644 --- a/two-sum/mrlee7.py +++ b/two-sum/mrlee7.py @@ -7,4 +7,4 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(0, len(nums) - 1): for j in range(i + 1, len(nums)): if (target - nums[i]) == nums[j]: - return [i, j] \ No newline at end of file + return [i, j] From 472e827a1f14cc3ff884b0e969faa6350920486c Mon Sep 17 00:00:00 2001 From: mrlee7 Date: Fri, 6 Mar 2026 23:34:44 +0900 Subject: [PATCH 3/4] add two sum annotations --- two-sum/mrlee7.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/two-sum/mrlee7.py b/two-sum/mrlee7.py index 8ada5a68f0..a208678160 100644 --- a/two-sum/mrlee7.py +++ b/two-sum/mrlee7.py @@ -2,8 +2,17 @@ class Solution: - def twoSum(self, nums: List[int], target: int) -> List[int]: + """ + Ideation: + target = x + y -> target - x = y + x 원소를 가장 바깥의 이터레이션에서 돌면서 하나씩 대입합니다. + 찾고자 하는 값이 (x,y) 쌍이므로, 두개의 인덱스를 찾기 위해 인덱스 기준으로 이터레이션을 수행합니다( enumerate 사용 가능). + y값이 찾아지면 당시의 x값의 인덱스와 함께 (index_of_x, index_of_y) 를 리스트로 반환합니다. + Time Complexity: O(N^2) + Space Complexity: O(1) + """ + def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(0, len(nums) - 1): for j in range(i + 1, len(nums)): if (target - nums[i]) == nums[j]: From 23666b2e32012e78ce5d8e257500ddf14fa776df Mon Sep 17 00:00:00 2001 From: mrlee7 Date: Fri, 6 Mar 2026 23:54:59 +0900 Subject: [PATCH 4/4] container duplicates solution --- contains-duplicate/mrlee7.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 contains-duplicate/mrlee7.py diff --git a/contains-duplicate/mrlee7.py b/contains-duplicate/mrlee7.py new file mode 100644 index 0000000000..6ce409b2f6 --- /dev/null +++ b/contains-duplicate/mrlee7.py @@ -0,0 +1,20 @@ +from typing import List + + +class Solution: + """ + Ideation: + 각 원소가 발견되면 hash map 에 해당하는 item 기반으로 flag를 세운다. + 해당 인덱스에서 flag가 이미 켜져있다면, 앞에서 탐색된 원소이므로 True를 반환한다. + 마지막까지 다 돌았는데 중복된 케이스가 없다면 False를 반환한다. + Time complexity: O(n) + Space complexity: O(n) + """ + + def containsDuplicate(self, nums: List[int]) -> bool: + seen = {} + for num in nums: + if num in seen: + return True + seen[num] = 1 + return False