From 31ea7ad521b5afd61678281044a2467df6485526 Mon Sep 17 00:00:00 2001 From: sejineer Date: Mon, 31 Mar 2025 22:00:43 +0900 Subject: [PATCH 1/3] contains-duplicate solution --- contains-duplicate/sejineer.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 contains-duplicate/sejineer.py diff --git a/contains-duplicate/sejineer.py b/contains-duplicate/sejineer.py new file mode 100644 index 000000000..ee4593a71 --- /dev/null +++ b/contains-duplicate/sejineer.py @@ -0,0 +1,18 @@ +""" +시간 복잡도 O(n) +공간 복잡도 O(n) + +코드 가독성 향상 코드 +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + return len(nums) != len(set(nums)) +""" +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + check = set([]) + for i in nums: + if i not in check: + check.add(i) + else: + return True + return False From 7d436fc28f661a7d0633f8a0c2834370443e5574 Mon Sep 17 00:00:00 2001 From: sejineer Date: Fri, 4 Apr 2025 22:17:52 +0900 Subject: [PATCH 2/3] two-sum solution --- two-sum/sejineer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 two-sum/sejineer.py diff --git a/two-sum/sejineer.py b/two-sum/sejineer.py new file mode 100644 index 000000000..cda5c6668 --- /dev/null +++ b/two-sum/sejineer.py @@ -0,0 +1,14 @@ +""" +시간 복잡도 O(n) +공간 복잡도 O(n) +""" +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + nums_map = {} + + for i, v in enumerate(nums): + x = target - v + if x in nums_map: + j = nums_map[x] + return [j, i] + nums_map[v] = i \ No newline at end of file From 3d032d8e0065bbbfd0fb8a0b25cbd76dfeba5a5f Mon Sep 17 00:00:00 2001 From: sejineer Date: Fri, 4 Apr 2025 22:19:19 +0900 Subject: [PATCH 3/3] two-sum solution fix lint --- two-sum/sejineer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/sejineer.py b/two-sum/sejineer.py index cda5c6668..3484b2708 100644 --- a/two-sum/sejineer.py +++ b/two-sum/sejineer.py @@ -11,4 +11,4 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if x in nums_map: j = nums_map[x] return [j, i] - nums_map[v] = i \ No newline at end of file + nums_map[v] = i