From 1ab2ab92c684e9516aa49000a97dc31b239fb0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Wed, 9 Apr 2025 17:04:41 +0900 Subject: [PATCH 1/6] solve: valid anagram --- valid-anagram/paran22.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 valid-anagram/paran22.py diff --git a/valid-anagram/paran22.py b/valid-anagram/paran22.py new file mode 100644 index 000000000..e9b119ebf --- /dev/null +++ b/valid-anagram/paran22.py @@ -0,0 +1,8 @@ +from collections import Counter + +class Solution: + # time complexity: O(n) + def isAnagram(self, s: str, t: str) -> bool: + return Counter(s) == Counter(t) + + \ No newline at end of file From cc399a278f0c34e27fecab04ad017e75cf8f7027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Wed, 9 Apr 2025 17:39:42 +0900 Subject: [PATCH 2/6] solve: climbing stairs --- climbing-stairs/paran22.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 climbing-stairs/paran22.py diff --git a/climbing-stairs/paran22.py b/climbing-stairs/paran22.py new file mode 100644 index 000000000..64d3d11c3 --- /dev/null +++ b/climbing-stairs/paran22.py @@ -0,0 +1,12 @@ +class Solution: + # time complexity: O(n) + def climbStairs(self, n: int) -> int: + if n <= 2: + return n + + prev1, prev2 = 1, 2 + for _ in range(3, n + 1): + current = prev1 + prev2 + prev1, prev2 = prev2, current + return prev2 + \ No newline at end of file From 3742f2947d3077f3a591be562004fc90edd58072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Thu, 10 Apr 2025 09:48:58 +0900 Subject: [PATCH 3/6] solve: product of array except self --- product-of-array-except-self/paran22.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 product-of-array-except-self/paran22.py diff --git a/product-of-array-except-self/paran22.py b/product-of-array-except-self/paran22.py new file mode 100644 index 000000000..56e6eef88 --- /dev/null +++ b/product-of-array-except-self/paran22.py @@ -0,0 +1,18 @@ +class Solution: + # time complexity: O(n) + def productExceptSelf(self, nums: List[int]) -> List[int]: + n = len(nums) + answer = [1] * n + + prefix = 1 + for i in range(n): + answer[i] = prefix + prefix *= nums[i] + + suffix = 1 + for i in range(n-1, -1, -1): + answer[i] *= suffix + suffix *= nums[i] + + return answer + From b409b6a71c7ec3b721b46aad63500fc269c1f5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Thu, 10 Apr 2025 10:14:46 +0900 Subject: [PATCH 4/6] solve: 3sum --- 3sum/paran22.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 3sum/paran22.py diff --git a/3sum/paran22.py b/3sum/paran22.py new file mode 100644 index 000000000..3b3d6f93f --- /dev/null +++ b/3sum/paran22.py @@ -0,0 +1,27 @@ +class Solution: + # time complexity: O(n^2) + def threeSum(self, nums: List[int]) -> List[List[int]]: + nums.sort() + answer = set() + + for i in range(len(nums) - 2): + if i > 0 and nums[i] == nums[i - 1]: + continue + + left, right = i + 1, len(nums) - 1 + while left < right: + sum = nums[i] + nums[left] + nums[right] + if sum == 0: + answer.add((nums[i], nums[left], nums[right])) + left += 1 + right -= 1 + elif sum > 0: + right -= 1 + elif sum < 0: + left += 1 + + return [list(x) for x in answer] + + + + \ No newline at end of file From 24d7769fc70ffeb20da8a0dc9bafe17eb33058d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Thu, 10 Apr 2025 10:28:34 +0900 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=EA=B3=B5=EB=B0=B1=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3sum/paran22.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/3sum/paran22.py b/3sum/paran22.py index 3b3d6f93f..11ccdce7a 100644 --- a/3sum/paran22.py +++ b/3sum/paran22.py @@ -21,7 +21,3 @@ def threeSum(self, nums: List[int]) -> List[List[int]]: left += 1 return [list(x) for x in answer] - - - - \ No newline at end of file From 68a7daa8abe200b00082c9041d23b866d30a44f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Thu, 10 Apr 2025 10:31:37 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=EC=A4=84=EB=B0=94=EA=BF=88=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3sum/paran22.py | 1 + climbing-stairs/paran22.py | 1 - valid-anagram/paran22.py | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/3sum/paran22.py b/3sum/paran22.py index 11ccdce7a..46c2afc08 100644 --- a/3sum/paran22.py +++ b/3sum/paran22.py @@ -21,3 +21,4 @@ def threeSum(self, nums: List[int]) -> List[List[int]]: left += 1 return [list(x) for x in answer] + diff --git a/climbing-stairs/paran22.py b/climbing-stairs/paran22.py index 64d3d11c3..760c39966 100644 --- a/climbing-stairs/paran22.py +++ b/climbing-stairs/paran22.py @@ -9,4 +9,3 @@ def climbStairs(self, n: int) -> int: current = prev1 + prev2 prev1, prev2 = prev2, current return prev2 - \ No newline at end of file diff --git a/valid-anagram/paran22.py b/valid-anagram/paran22.py index e9b119ebf..46c71857f 100644 --- a/valid-anagram/paran22.py +++ b/valid-anagram/paran22.py @@ -5,4 +5,3 @@ class Solution: def isAnagram(self, s: str, t: str) -> bool: return Counter(s) == Counter(t) - \ No newline at end of file