From 1f7be88bbf9127b0892008eee062553bcddbfba9 Mon Sep 17 00:00:00 2001 From: YOOHYOJEONG Date: Mon, 9 Mar 2026 23:08:38 +0900 Subject: [PATCH 1/2] week02_1_2_3_solution --- climbing-stairs/YOOHYOJEONG.py | 12 ++++++++++++ product-of-array-except-self/YOOHYOJEONG.py | 19 +++++++++++++++++++ valid-anagram/YOOHYOJEONG.py | 8 ++++++++ 3 files changed, 39 insertions(+) create mode 100644 climbing-stairs/YOOHYOJEONG.py create mode 100644 product-of-array-except-self/YOOHYOJEONG.py create mode 100644 valid-anagram/YOOHYOJEONG.py diff --git a/climbing-stairs/YOOHYOJEONG.py b/climbing-stairs/YOOHYOJEONG.py new file mode 100644 index 0000000000..96fb6b36c2 --- /dev/null +++ b/climbing-stairs/YOOHYOJEONG.py @@ -0,0 +1,12 @@ +# https://leetcode.com/problems/climbing-stairs + +class Solution(object): + def climbStairs(self, n): + if n <= 2: + return n + + a, b = 1, 2 + for i in range(3, n+1): + a, b = b, a+b + + return b diff --git a/product-of-array-except-self/YOOHYOJEONG.py b/product-of-array-except-self/YOOHYOJEONG.py new file mode 100644 index 0000000000..17cfeeb354 --- /dev/null +++ b/product-of-array-except-self/YOOHYOJEONG.py @@ -0,0 +1,19 @@ +# https://leetcode.com/problems/product-of-array-except-self/ + +class Solution(object): + def productExceptSelf(self, nums): + + n = len(nums) + output = [1] * n + + left = 1 + for i in range(n): + output[i] = left + left *= nums[i] + + right = 1 + for i in range(n-1, -1, -1): + output[i] *= right + right *= nums[i] + + return output diff --git a/valid-anagram/YOOHYOJEONG.py b/valid-anagram/YOOHYOJEONG.py new file mode 100644 index 0000000000..b472b6e47e --- /dev/null +++ b/valid-anagram/YOOHYOJEONG.py @@ -0,0 +1,8 @@ +# https://leetcode.com/problems/valid-anagram/ + +class Solution(object): + def isAnagram(self, s, t): + if sorted(s) == sorted(t): + return True + else: + return False From f02e639c80544962ddb6ddf0baec8cfe160d2a53 Mon Sep 17 00:00:00 2001 From: YOOHYOJEONG Date: Fri, 13 Mar 2026 15:06:19 +0900 Subject: [PATCH 2/2] week02_4_5_solution --- 3sum/YOOHYOJEONG.py | 37 ++++++++++++++++++++++ validate-binary-search-tree/YOOHYOJEONG.py | 25 +++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 3sum/YOOHYOJEONG.py create mode 100644 validate-binary-search-tree/YOOHYOJEONG.py diff --git a/3sum/YOOHYOJEONG.py b/3sum/YOOHYOJEONG.py new file mode 100644 index 0000000000..eccba2c35f --- /dev/null +++ b/3sum/YOOHYOJEONG.py @@ -0,0 +1,37 @@ +# https://leetcode.com/problems/3sum + +class Solution(object): + def threeSum(self, nums): + nums.sort() + result = [] + + for i in range(len(nums) - 2): + + if i > 0 and nums[i] == nums[i - 1]: + continue + + left = i + 1 + right = len(nums) - 1 + + while left < right: + total = nums[i] + nums[left] + nums[right] + + if total < 0: + left += 1 + + elif total > 0: + right -= 1 + + else: + result.append([nums[i], nums[left], nums[right]]) + + while left < right and nums[left] == nums[left + 1]: + left += 1 + + while left < right and nums[right] == nums[right - 1]: + right -= 1 + + left += 1 + right -= 1 + + return result diff --git a/validate-binary-search-tree/YOOHYOJEONG.py b/validate-binary-search-tree/YOOHYOJEONG.py new file mode 100644 index 0000000000..17d801f5da --- /dev/null +++ b/validate-binary-search-tree/YOOHYOJEONG.py @@ -0,0 +1,25 @@ +# https://leetcode.com/problems/validate-binary-search-tree/description/ + +# 도저히 안풀어서 지피티의 도움을 받았습니다..TT +# 새로 알게 된 개념 +# 이진 트리는 하나의 노드가 최대 두 개의 자식 노드를 가지는 트리 자료구조 +# 두 개의 포인터를 가지고 있으며, 루트에서 시작해서 아래로 내려가는 계층 구조 +# Binary Search Tree(BST)는 이진 트리의 한 종류로 어떤 노드의 왼쪽 서브트리에 있는 모든 값은 해당 노드보다 작고 오른쪽 서브트리에 있는 모든 값은 해당 노드보다 큼 +# 이 문제는 주어진 트리가 이 규칙을 만족하는지 확인하는 문제임 +# 각 노드가 가질 수 있는 허용 범위(min, max)를 유지하면서 검사해야 함 +class Solution: + def isValidBST(self, root): + + def dfs(node, low, high): + if not node: + return True + + if node.val <= low or node.val >= high: + return False + + return ( + dfs(node.left, low, node.val) and + dfs(node.right, node.val, high) + ) + + return dfs(root, float("-inf"), float("inf"))