From 9c76a62865d105579f82c4c0104c6fcf33a19f99 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Tue, 16 Dec 2025 21:06:21 +0900 Subject: [PATCH 1/2] [:solved] #222 --- valid-parentheses/ppxyn1.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 valid-parentheses/ppxyn1.py diff --git a/valid-parentheses/ppxyn1.py b/valid-parentheses/ppxyn1.py new file mode 100644 index 0000000000..191bb518d1 --- /dev/null +++ b/valid-parentheses/ppxyn1.py @@ -0,0 +1,22 @@ +# idea : stack + +class Solution: + def isValid(self, s: str) -> bool: + mapping = {"(": ")", "{": "}", "[": "]"} + stack = [] + + for ch in s: + if ch in mapping: + stack.append(ch) + else: + if not stack: + return False + if mapping[stack.pop()] != ch: + return False + if stack: + return False + + return True + + + From 4442084045223dfcae74034bddac88bb01139dd8 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Sat, 20 Dec 2025 19:03:16 +0900 Subject: [PATCH 2/2] [:solved] 3 problems --- container-with-most-water/ppxyn1.py | 15 +++++++++++ longest-increasing-subsequence/ppxyn1.py | 13 +++++++++ spiral-matrix/ppxyn1.py | 34 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 container-with-most-water/ppxyn1.py create mode 100644 longest-increasing-subsequence/ppxyn1.py create mode 100644 spiral-matrix/ppxyn1.py diff --git a/container-with-most-water/ppxyn1.py b/container-with-most-water/ppxyn1.py new file mode 100644 index 0000000000..82a177cf12 --- /dev/null +++ b/container-with-most-water/ppxyn1.py @@ -0,0 +1,15 @@ +# idea : two-pointer +class Solution: + def maxArea(self, height: List[int]) -> int: + max_area = 0 + start, end = 0, len(height) - 1 + while start < end: + area = (end - start) * min(height[start], height[end]) + max_area = max(max_area, area) + if height[start] < height[end]: + start += 1 + else: + end -= 1 + return max_area + + diff --git a/longest-increasing-subsequence/ppxyn1.py b/longest-increasing-subsequence/ppxyn1.py new file mode 100644 index 0000000000..4205335aa9 --- /dev/null +++ b/longest-increasing-subsequence/ppxyn1.py @@ -0,0 +1,13 @@ +# idea: DP +# O(N^2) +class Solution: + def lengthOfLIS(self, nums: List[int]) -> int: + LIS = [1] * len(nums) + for i in range(len(nums) - 1, -1, -1): + for j in range(i+1, len(nums)): + if nums[i] < nums[j]: + LIS[i] = max(LIS[i], 1+LIS[j]) + return max(LIS) + + + diff --git a/spiral-matrix/ppxyn1.py b/spiral-matrix/ppxyn1.py new file mode 100644 index 0000000000..3cc8fea6d4 --- /dev/null +++ b/spiral-matrix/ppxyn1.py @@ -0,0 +1,34 @@ +# idea : - +# O(m*n) +class Solution: + def spiralOrder(self, matrix: List[List[int]]) -> List[int]: + res = [] + left, right = 0, len(matrix[0]) + top, bottom = 0, len(matrix) + + while left < right and top < bottom: + # get every i in the top row + for i in range(left, right): + res.append(matrix[top][i]) + top+=1 + + # get every i in the right col + for i in range(top, bottom): + res.append(matrix[i][right - 1]) + right -= 1 + + if not (left < right and top < bottom): + break + #get every i in the bottom row + for i in range(right - 1, left - 1, -1): + res.append(matrix[bottom-1][i]) + bottom -= 1 + + # get every i in the left col + for i in range(bottom -1, top-1, -1): + res.append(matrix[i][left]) + left += 1 + return res + + +