From 7bc0b19db4632cfad585131fa0ae9bc2da5f76da Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Fri, 11 Apr 2025 19:09:19 +0900 Subject: [PATCH 01/10] valid-anagram --- valid-anagram/yyyyyyyyyKim.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 valid-anagram/yyyyyyyyyKim.py diff --git a/valid-anagram/yyyyyyyyyKim.py b/valid-anagram/yyyyyyyyyKim.py new file mode 100644 index 000000000..e69de29bb From 306ac378a73cc5940beea83c89d7500b9cf0ce8d Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 15:59:49 +0900 Subject: [PATCH 02/10] valid-anagram solution --- valid-anagram/yyyyyyyyyKim.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/valid-anagram/yyyyyyyyyKim.py b/valid-anagram/yyyyyyyyyKim.py index e69de29bb..ffdcf4647 100644 --- a/valid-anagram/yyyyyyyyyKim.py +++ b/valid-anagram/yyyyyyyyyKim.py @@ -0,0 +1,6 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + + if sorted(s) == sorted(t): + return True + return False From abda69942cf47082370d938da0cc60cda0453ed2 Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 16:06:19 +0900 Subject: [PATCH 03/10] climbing-stairs solution --- climbing-stairs/yyyyyyyyyKim.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 climbing-stairs/yyyyyyyyyKim.py diff --git a/climbing-stairs/yyyyyyyyyKim.py b/climbing-stairs/yyyyyyyyyKim.py new file mode 100644 index 000000000..80163fbbc --- /dev/null +++ b/climbing-stairs/yyyyyyyyyKim.py @@ -0,0 +1,12 @@ +class Solution: + def climbStairs(self, n: int) -> int: + + if n <= 3: + return n + + a, b = 1, 2 + + for i in range(3,n+1): + a, b = b, a+b + + return b \ No newline at end of file From e7d42348ad50d48e5a818ed747062ad4c6ab762f Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 16:08:10 +0900 Subject: [PATCH 04/10] =?UTF-8?q?climbing-stairs=20solution=20=EA=B0=9C?= =?UTF-8?q?=ED=96=89=EB=AC=B8=EC=9E=90=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/yyyyyyyyyKim.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/climbing-stairs/yyyyyyyyyKim.py b/climbing-stairs/yyyyyyyyyKim.py index 80163fbbc..31f786632 100644 --- a/climbing-stairs/yyyyyyyyyKim.py +++ b/climbing-stairs/yyyyyyyyyKim.py @@ -9,4 +9,5 @@ def climbStairs(self, n: int) -> int: for i in range(3,n+1): a, b = b, a+b - return b \ No newline at end of file + return b + \ No newline at end of file From 6e9b6df1b607df7c283db2c81fd4effc8cfa59e6 Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 16:22:24 +0900 Subject: [PATCH 05/10] =?UTF-8?q?climbing-stairs=20solution=20=EA=B0=9C?= =?UTF-8?q?=ED=96=89=EB=AC=B8=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/yyyyyyyyyKim.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/climbing-stairs/yyyyyyyyyKim.py b/climbing-stairs/yyyyyyyyyKim.py index 31f786632..80163fbbc 100644 --- a/climbing-stairs/yyyyyyyyyKim.py +++ b/climbing-stairs/yyyyyyyyyKim.py @@ -9,5 +9,4 @@ def climbStairs(self, n: int) -> int: for i in range(3,n+1): a, b = b, a+b - return b - \ No newline at end of file + return b \ No newline at end of file From 13977bc7c497100eac2ee6309850ad3ccf5a3d82 Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 16:31:51 +0900 Subject: [PATCH 06/10] =?UTF-8?q?climbing-stairs=20solution=20=EA=B0=9C?= =?UTF-8?q?=ED=96=89=EB=AC=B8=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/yyyyyyyyyKim.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/climbing-stairs/yyyyyyyyyKim.py b/climbing-stairs/yyyyyyyyyKim.py index 80163fbbc..31f786632 100644 --- a/climbing-stairs/yyyyyyyyyKim.py +++ b/climbing-stairs/yyyyyyyyyKim.py @@ -9,4 +9,5 @@ def climbStairs(self, n: int) -> int: for i in range(3,n+1): a, b = b, a+b - return b \ No newline at end of file + return b + \ No newline at end of file From af9250600a84ff1768ff01ad4a8e39342f7a4288 Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 16:34:05 +0900 Subject: [PATCH 07/10] =?UTF-8?q?climbing-stairs=20solution=20=EA=B0=9C?= =?UTF-8?q?=ED=96=89=EB=AC=B8=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/yyyyyyyyyKim.py | 1 - 1 file changed, 1 deletion(-) diff --git a/climbing-stairs/yyyyyyyyyKim.py b/climbing-stairs/yyyyyyyyyKim.py index 31f786632..255a9d44d 100644 --- a/climbing-stairs/yyyyyyyyyKim.py +++ b/climbing-stairs/yyyyyyyyyKim.py @@ -10,4 +10,3 @@ def climbStairs(self, n: int) -> int: a, b = b, a+b return b - \ No newline at end of file From 90bea1df4673ca0ecf0a7d6fa24042c8addc754b Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 16:46:18 +0900 Subject: [PATCH 08/10] product-of-array-except-self solution --- product-of-array-except-self/yyyyyyyyyKim.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 product-of-array-except-self/yyyyyyyyyKim.py diff --git a/product-of-array-except-self/yyyyyyyyyKim.py b/product-of-array-except-self/yyyyyyyyyKim.py new file mode 100644 index 000000000..4c3c0b0f9 --- /dev/null +++ b/product-of-array-except-self/yyyyyyyyyKim.py @@ -0,0 +1,16 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + + answer = [1]*len(nums) + + left = 1 + for i in range(len(nums)): + answer[i] *= left + left *= nums[i] + + right = 1 + for i in range(len(nums)-1,-1,-1): + answer[i] *= right + right *= nums[i] + + return answer From 590132471fa9e527338e567a832cd7e46637a357 Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 16:52:54 +0900 Subject: [PATCH 09/10] 3sum solution --- 3sum/yyyyyyyyyKim.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 3sum/yyyyyyyyyKim.py diff --git a/3sum/yyyyyyyyyKim.py b/3sum/yyyyyyyyyKim.py new file mode 100644 index 000000000..c2f63ff85 --- /dev/null +++ b/3sum/yyyyyyyyyKim.py @@ -0,0 +1,36 @@ +class Solution: + def threeSum(self, nums: List[int]) -> List[List[int]]: + + answer = [] + + # 정렬 + nums.sort() + + for i in range(len(nums)-2): + # i 중복제거 + if i > 0 and nums[i] == nums[i - 1]: + continue + + left = i+1 + right = len(nums)-1 + + while left < right: + if nums[i] + nums[left] + nums[right] == 0: + answer.append([nums[i],nums[left],nums[right]]) + + # left 중복제거 + while left < right and nums[left] == nums[left+1]: + left += 1 + # right 중복제거 + while left < right and nums[right] == nums[right-1]: + right -= 1 + + left += 1 + right -= 1 + + elif nums[i] + nums[left] + nums[right] < 0: + left += 1 + else: + right -= 1 + + return answer From ae0d55df9f8701285ab903e4372a4bba217af110 Mon Sep 17 00:00:00 2001 From: yyyyyyyyy Date: Sat, 12 Apr 2025 21:47:02 +0900 Subject: [PATCH 10/10] validate-binary-search-tree solution --- validate-binary-search-tree/yyyyyyyyyKim.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 validate-binary-search-tree/yyyyyyyyyKim.py diff --git a/validate-binary-search-tree/yyyyyyyyyKim.py b/validate-binary-search-tree/yyyyyyyyyKim.py new file mode 100644 index 000000000..84e7bdc3a --- /dev/null +++ b/validate-binary-search-tree/yyyyyyyyyKim.py @@ -0,0 +1,19 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def isValidBST(self, root: Optional[TreeNode]) -> bool: + + # 깊이우선탐색(dfs), 재귀 + def dfs(node, min_val, max_val): + if not node: + return True + if not (min_val < node.val < max_val): + return False + return (dfs(node.left, min_val, node.val) and + dfs(node.right, node.val, max_val)) + + return dfs(root, float('-inf'), float('inf'))