From 33de329be19f3a1bb1367cbc07fdb6111e7791e7 Mon Sep 17 00:00:00 2001 From: hestia-park Date: Tue, 1 Apr 2025 21:13:30 -0400 Subject: [PATCH 1/3] A solution for Contains Duplicate #217 --- contains-duplicate/hestia-park.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 contains-duplicate/hestia-park.py diff --git a/contains-duplicate/hestia-park.py b/contains-duplicate/hestia-park.py new file mode 100644 index 000000000..74fefc4f2 --- /dev/null +++ b/contains-duplicate/hestia-park.py @@ -0,0 +1,3 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + return len(nums) != len(set(nums)) \ No newline at end of file From bcfdf6956303964d463a15776aec037c84ffec8d Mon Sep 17 00:00:00 2001 From: hestia-park Date: Tue, 8 Apr 2025 16:12:34 -0400 Subject: [PATCH 2/3] add newline A solution for Contains Duplicate #217 --- contains-duplicate/hestia-park.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contains-duplicate/hestia-park.py b/contains-duplicate/hestia-park.py index 74fefc4f2..d41e60eb0 100644 --- a/contains-duplicate/hestia-park.py +++ b/contains-duplicate/hestia-park.py @@ -1,3 +1,5 @@ class Solution: def containsDuplicate(self, nums: List[int]) -> bool: - return len(nums) != len(set(nums)) \ No newline at end of file + return len(nums) != len(set(nums)) + + From 01f1f0d560bbb6b43ab3452f6ee62704faef35d7 Mon Sep 17 00:00:00 2001 From: hestia-park Date: Tue, 8 Apr 2025 17:30:26 -0400 Subject: [PATCH 3/3] A 2week solution --- 3sum/hestia-park.py | 25 +++++++++++++++++++++ climbing-stairs/hestia-park.py | 21 +++++++++++++++++ product-of-array-except-self/hestia-park.py | 17 ++++++++++++++ valid-anagram/hestia-park.py | 9 ++++++++ validate-binary-search-tree/hestia-park.py | 12 ++++++++++ 5 files changed, 84 insertions(+) create mode 100644 3sum/hestia-park.py create mode 100644 climbing-stairs/hestia-park.py create mode 100644 product-of-array-except-self/hestia-park.py create mode 100644 valid-anagram/hestia-park.py create mode 100644 validate-binary-search-tree/hestia-park.py diff --git a/3sum/hestia-park.py b/3sum/hestia-park.py new file mode 100644 index 000000000..565abffa3 --- /dev/null +++ b/3sum/hestia-park.py @@ -0,0 +1,25 @@ +class Solution: + def threeSum(self, nums: List[int]) -> List[List[int]]: + nums.sort() + answer=set() + for i in range(len(nums)): + if nums[i] > 0: + break # 이후 숫자는 모두 양수 → 합이 0 불가능 + if i > 0 and nums[i] == nums[i - 1]: + continue + + left, right = i + 1, len(nums) - 1 + while left < right: + term = nums[i] + nums[left] + nums[right] + if term == 0: + answer.add((nums[i], nums[left], nums[right])) + left += 1 + right -= 1 + elif term < 0: + left += 1 + else: + right -= 1 + + return [list(triplet) for triplet in answer] + + diff --git a/climbing-stairs/hestia-park.py b/climbing-stairs/hestia-park.py new file mode 100644 index 000000000..56bad6352 --- /dev/null +++ b/climbing-stairs/hestia-park.py @@ -0,0 +1,21 @@ +class Solution: + def climbStairs(self, n: int) -> int: + if n <= 1: + return 1 + + # dp = [0] * (n + 1) + # dp[0] = 1 + # dp[1] = 1 + + # for i in range(2, n + 1): + # dp[i] = dp[i - 1] + dp[i - 2] + + # return dp[n] + # optima sol + dp_0,dp_1=1,1 + for _ in range(2,n+1): + dp_0,dp_1=dp_1,dp_0+dp_1 + return dp_1 + + + diff --git a/product-of-array-except-self/hestia-park.py b/product-of-array-except-self/hestia-park.py new file mode 100644 index 000000000..e7f8c4e60 --- /dev/null +++ b/product-of-array-except-self/hestia-park.py @@ -0,0 +1,17 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + n=len(nums) + answer=[1] * n + #for left + for i in range(1,n): + answer[i]=answer[i-1]*nums[i-1] + + tail=1 + #for right + for i in range(n-1,-1,-1): + answer[i] *= tail + tail *= nums[i] + return answer + + + diff --git a/valid-anagram/hestia-park.py b/valid-anagram/hestia-park.py new file mode 100644 index 000000000..dc1ae53fe --- /dev/null +++ b/valid-anagram/hestia-park.py @@ -0,0 +1,9 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + if len(s) != len(t): + return False + counter_s=Counter(s) + counter_t=Counter(t) + return counter_s == counter_t + + diff --git a/validate-binary-search-tree/hestia-park.py b/validate-binary-search-tree/hestia-park.py new file mode 100644 index 000000000..b4df31bb0 --- /dev/null +++ b/validate-binary-search-tree/hestia-park.py @@ -0,0 +1,12 @@ +class Solution: + def isValidBST(self, root: Optional[TreeNode]) -> bool: + def check(node, min_val, max_val): + if not node: + return True + if not (min_val < node.val < max_val): + return False + return check(node.left, min_val, node.val) and check(node.right, node.val, max_val) + + return check(root, float('-inf'), float('inf')) + +