From 3f859c0606e17720bdbc22a0432b2bdc6a30cad8 Mon Sep 17 00:00:00 2001 From: yejin Date: Sun, 3 Aug 2025 12:28:19 +0900 Subject: [PATCH 01/12] climbing staris solution --- climbing-stairs/devyejin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 climbing-stairs/devyejin.py diff --git a/climbing-stairs/devyejin.py b/climbing-stairs/devyejin.py new file mode 100644 index 000000000..13f60f69f --- /dev/null +++ b/climbing-stairs/devyejin.py @@ -0,0 +1,16 @@ +class Solution(object): + def climbStairs(self, n): + """ + :type n: int + :rtype: int + """ + if n <= 2: + return n + + dp = [0] * (n + 1) + dp[1], dp[2] = 1, 2 + + for i in range(3, n + 1): + dp[i] = dp[i-1] + dp[i-2] + + return dp[n] From 564f163bc67bd6f27df66909b92b6f60ece0cd26 Mon Sep 17 00:00:00 2001 From: yejin Date: Sun, 3 Aug 2025 13:26:00 +0900 Subject: [PATCH 02/12] product of array except self solution --- product-of-array-except-self/devyejin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 product-of-array-except-self/devyejin.py diff --git a/product-of-array-except-self/devyejin.py b/product-of-array-except-self/devyejin.py new file mode 100644 index 000000000..312d40868 --- /dev/null +++ b/product-of-array-except-self/devyejin.py @@ -0,0 +1,16 @@ +class Solution: + def productExceptSelf(self, nums): + n = len(nums) + result = [1] * n + + left_product = 1 + for i in range(n): + result[i] = left_product + left_product *= nums[i] + + right_product = 1 + for i in range(n - 1, -1, -1): + result[i] *= right_product + right_product *= nums[i] + + return result \ No newline at end of file From 64ebc44892ed06b23dcfad5d976a6a644fb5ec9a Mon Sep 17 00:00:00 2001 From: yejin Date: Sun, 3 Aug 2025 15:56:11 +0900 Subject: [PATCH 03/12] 3 sum solution --- 3sum/devyejin.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 3sum/devyejin.py diff --git a/3sum/devyejin.py b/3sum/devyejin.py new file mode 100644 index 000000000..9c1e1fc83 --- /dev/null +++ b/3sum/devyejin.py @@ -0,0 +1,36 @@ +class Solution: + def threeSum(self, nums: List[int]) -> List[List[int]]: + nums.sort() # O(n) + + n = len(nums) + result = [] + + for i in range(n - 2): + # target을 잡을때도 이전에 구했다면 패스 + if i > 0 and nums[i] == nums[i - 1]: + continue + + target = - nums[i] + left, right = i + 1, n - 1 + + while left < right: + two_sum = nums[left] + nums[right] + + if two_sum == target: + 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 + + elif two_sum < target: + left += 1 + else: + right -= 1 + + return result \ No newline at end of file From 53f0a11dcd5b53a480f382f0b0361ef7878f4c76 Mon Sep 17 00:00:00 2001 From: yejin Date: Mon, 4 Aug 2025 01:28:34 +0900 Subject: [PATCH 04/12] validate binary search tree --- validate-binary-search-tree/devyejin.py | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 validate-binary-search-tree/devyejin.py diff --git a/validate-binary-search-tree/devyejin.py b/validate-binary-search-tree/devyejin.py new file mode 100644 index 000000000..8896d61c7 --- /dev/null +++ b/validate-binary-search-tree/devyejin.py @@ -0,0 +1,51 @@ +# Definition for a binary tree node. +from collections import deque +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + +def list_to_tree(arr): + if not arr: + return None +# -> 레벨로 주고 있음 + root = TreeNode(arr[0]) + queue = deque([root]) # 큐에 root를 넣고 시작 queue = deque() queue.append(root)와 동일 + i = 1 + + while queue and i < len(arr): + current = queue.popleft() + + if i < len(arr) and arr[i] is not None: + current.left = TreeNode(arr[i]) + queue.append(current.left) + i += 1 + + if i < len(arr) and arr[i] is not None: + current.right = TreeNode(arr[i]) + queue.append(current.right) + i += 1 + + return root + + +class Solution: + def isValidBST(self, root: Optional[TreeNode]) -> bool: + self.prev = None + def inorder(node): + if not node: + return True + + # 왼쪽 서브트리 확인 + if not inorder(node.left): + return False + + # 현재 노드 값 확인 + if self.prev is not None and node.val <= self.prev: + return False + self.prev = node.val + + return inorder(node.right) + + return inorder(root) \ No newline at end of file From 432fda4d0ce3629a1df9117244b09a9a712b9652 Mon Sep 17 00:00:00 2001 From: yejin Date: Mon, 4 Aug 2025 23:32:37 +0900 Subject: [PATCH 05/12] valid palindrome solution --- valid-palindrome/devyejin.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 valid-palindrome/devyejin.py diff --git a/valid-palindrome/devyejin.py b/valid-palindrome/devyejin.py new file mode 100644 index 000000000..abfab60c0 --- /dev/null +++ b/valid-palindrome/devyejin.py @@ -0,0 +1,6 @@ +# isalnum() : 문자열이 영어, 한글 숫자 -> True , 아니라면 False +class Solution: + def isPalindrome(self, s: str) -> bool: + s = s.replace(" ", "") + changed_s = [c.lower() for c in s if c.isalnum()] + return changed_s == changed_s[::-1] From 10d6a8ff3d0255b55a2e42493fad741f70b34157 Mon Sep 17 00:00:00 2001 From: yejin Date: Mon, 4 Aug 2025 23:54:28 +0900 Subject: [PATCH 06/12] number of 1 bits solution --- number-of-1-bits/devyejin.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 number-of-1-bits/devyejin.py diff --git a/number-of-1-bits/devyejin.py b/number-of-1-bits/devyejin.py new file mode 100644 index 000000000..fa753925b --- /dev/null +++ b/number-of-1-bits/devyejin.py @@ -0,0 +1,7 @@ +class Solution: + def hammingWeight(self, n: int) -> int: + result = 0 + while n: + result += n % 2 + n //= 2 + return result \ No newline at end of file From b37d9d2555e15430cb9f40ec9584fdd71c1c0b03 Mon Sep 17 00:00:00 2001 From: yejin Date: Thu, 7 Aug 2025 11:28:59 +0900 Subject: [PATCH 07/12] =?UTF-8?q?=EA=B0=9C=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/devyejin.py | 1 + valid-palindrome/devyejin.py | 1 + 2 files changed, 2 insertions(+) diff --git a/climbing-stairs/devyejin.py b/climbing-stairs/devyejin.py index 13f60f69f..da2702416 100644 --- a/climbing-stairs/devyejin.py +++ b/climbing-stairs/devyejin.py @@ -14,3 +14,4 @@ def climbStairs(self, n): dp[i] = dp[i-1] + dp[i-2] return dp[n] + diff --git a/valid-palindrome/devyejin.py b/valid-palindrome/devyejin.py index abfab60c0..697adee86 100644 --- a/valid-palindrome/devyejin.py +++ b/valid-palindrome/devyejin.py @@ -4,3 +4,4 @@ def isPalindrome(self, s: str) -> bool: s = s.replace(" ", "") changed_s = [c.lower() for c in s if c.isalnum()] return changed_s == changed_s[::-1] + From 9c60339fc406f786fed44abc4b539ccd35fd7233 Mon Sep 17 00:00:00 2001 From: yejin Date: Thu, 7 Aug 2025 11:31:40 +0900 Subject: [PATCH 08/12] =?UTF-8?q?=EA=B0=9C=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3sum/devyejin.py | 2 +- number-of-1-bits/devyejin.py | 2 +- product-of-array-except-self/devyejin.py | 2 +- valid-palindrome/devyejin.py | 1 - validate-binary-search-tree/devyejin.py | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/3sum/devyejin.py b/3sum/devyejin.py index 9c1e1fc83..c77a89809 100644 --- a/3sum/devyejin.py +++ b/3sum/devyejin.py @@ -33,4 +33,4 @@ def threeSum(self, nums: List[int]) -> List[List[int]]: else: right -= 1 - return result \ No newline at end of file + return result diff --git a/number-of-1-bits/devyejin.py b/number-of-1-bits/devyejin.py index fa753925b..2ebe62f61 100644 --- a/number-of-1-bits/devyejin.py +++ b/number-of-1-bits/devyejin.py @@ -4,4 +4,4 @@ def hammingWeight(self, n: int) -> int: while n: result += n % 2 n //= 2 - return result \ No newline at end of file + return result diff --git a/product-of-array-except-self/devyejin.py b/product-of-array-except-self/devyejin.py index 312d40868..f247f1829 100644 --- a/product-of-array-except-self/devyejin.py +++ b/product-of-array-except-self/devyejin.py @@ -13,4 +13,4 @@ def productExceptSelf(self, nums): result[i] *= right_product right_product *= nums[i] - return result \ No newline at end of file + return result diff --git a/valid-palindrome/devyejin.py b/valid-palindrome/devyejin.py index 697adee86..abfab60c0 100644 --- a/valid-palindrome/devyejin.py +++ b/valid-palindrome/devyejin.py @@ -4,4 +4,3 @@ def isPalindrome(self, s: str) -> bool: s = s.replace(" ", "") changed_s = [c.lower() for c in s if c.isalnum()] return changed_s == changed_s[::-1] - diff --git a/validate-binary-search-tree/devyejin.py b/validate-binary-search-tree/devyejin.py index 8896d61c7..00213b8ad 100644 --- a/validate-binary-search-tree/devyejin.py +++ b/validate-binary-search-tree/devyejin.py @@ -48,4 +48,4 @@ def inorder(node): return inorder(node.right) - return inorder(root) \ No newline at end of file + return inorder(root) From de5164c2572d319ff0c69a6555bfca753f7bbd75 Mon Sep 17 00:00:00 2001 From: yejin Date: Sat, 9 Aug 2025 23:23:16 +0900 Subject: [PATCH 09/12] decode ways solutions --- decode-ways/devyejin..py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 decode-ways/devyejin..py diff --git a/decode-ways/devyejin..py b/decode-ways/devyejin..py new file mode 100644 index 000000000..62f7c9039 --- /dev/null +++ b/decode-ways/devyejin..py @@ -0,0 +1,24 @@ +class Solution: + def numDecodings(self, s: str) -> int: + + if not s or s[0] == "0": + return 0 + + n = len(s) + dp = [0] * (n + 1) + + dp[0] = 1 + dp[1] = 1 + + for i in range(2, n + 1): + if s[i - 1] != "0": + dp[i] += dp[i - 1] + + two_digit = int(s[i - 2: i]) + if 10 <= two_digit <= 26: + dp[i] += dp[i - 2] + + return dp[n] + + + From 66335b3f17c20da999d9b69c45d1f211e1782a70 Mon Sep 17 00:00:00 2001 From: yejin Date: Sat, 9 Aug 2025 23:27:50 +0900 Subject: [PATCH 10/12] =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=97=B0=EC=82=B0?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-palindrome/devyejin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/valid-palindrome/devyejin.py b/valid-palindrome/devyejin.py index abfab60c0..719a2ed56 100644 --- a/valid-palindrome/devyejin.py +++ b/valid-palindrome/devyejin.py @@ -1,6 +1,5 @@ # isalnum() : 문자열이 영어, 한글 숫자 -> True , 아니라면 False class Solution: def isPalindrome(self, s: str) -> bool: - s = s.replace(" ", "") changed_s = [c.lower() for c in s if c.isalnum()] return changed_s == changed_s[::-1] From 45ff2a226f22f284e97cf561f5a90f0dd5fa9d11 Mon Sep 17 00:00:00 2001 From: yejin Date: Sun, 10 Aug 2025 16:22:49 +0900 Subject: [PATCH 11/12] combination sum solution --- combination-sum/devyejin.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 combination-sum/devyejin.py diff --git a/combination-sum/devyejin.py b/combination-sum/devyejin.py new file mode 100644 index 000000000..68824d817 --- /dev/null +++ b/combination-sum/devyejin.py @@ -0,0 +1,20 @@ +class Solution: + def combinationSum(self, candidates: list[int], target: int) -> list[list[int]]: + + def backtracking(start, total, result): + if total == target: + answer.append(result[:]) + return + + if sum(result) > target: + return + + for i in range(start, len(candidates)): + result.append(candidates[i]) + backtracking(i, total + candidates[i], result) + result.pop() + + answer = [] + backtracking(0, 0, []) + return answer + From ae732698b799e760f4447eb86ef9626e1b28256b Mon Sep 17 00:00:00 2001 From: yejin Date: Sun, 10 Aug 2025 19:49:15 +0900 Subject: [PATCH 12/12] maximum subarray solution --- maximum-subarray/devyejin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 maximum-subarray/devyejin.py diff --git a/maximum-subarray/devyejin.py b/maximum-subarray/devyejin.py new file mode 100644 index 000000000..1d0ddeb82 --- /dev/null +++ b/maximum-subarray/devyejin.py @@ -0,0 +1,10 @@ +class Solution: + def maxSubArray(self, nums: list[int]) -> int: + dp = [0] * len(nums) + dp[0] = nums[0] + + for i in range(1, len(nums)): + dp[i] = max(nums[i], dp[i - 1] + nums[i]) + + return max(dp) +