From dbde40d2f7870495b2902e1ee88ffa0cee4d6df0 Mon Sep 17 00:00:00 2001 From: Yerim Moon Date: Fri, 13 Mar 2026 16:20:43 -0700 Subject: [PATCH 1/4] climing stairs solution --- climbing-stairs/yerim01.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 climbing-stairs/yerim01.py diff --git a/climbing-stairs/yerim01.py b/climbing-stairs/yerim01.py new file mode 100644 index 0000000000..5cee23f7ac --- /dev/null +++ b/climbing-stairs/yerim01.py @@ -0,0 +1,34 @@ +# Goal: Given n steps, return the number of distinct ways you can climb to the top. +# Constraints: +# - You can climb either 1 or 2 steps at each time. +# - 1 <= n <= 45 +# Approach: +# f(n) = number of ways to reach step n. +# The last move must be from step n-1 or step n-2. +# Therefore, f(n) = f(n-1) + f(n-2). +# Base case - f(1) = 1, f(2) = 2. +# Use two variables prev1&prev2 to track the number of of f(n-1)&f(n-2). +# Iterate a loop, staring from 3. +# Store prev1 into temp. +# Update prev1&prev2. +# Return prev1. + +# Time complexity: O(n) +# - We iterate once +# Space complexity: O(1) +# - Only using variables + +class Solution: + def climbStairs(self, n: int) -> int: + if n <= 2: + return n + + prev1 = 2 + prev2 = 1 + + for i in range(3, n+1): + temp = prev1 + prev1 = prev2 + prev1 + prev2 = temp + + return prev1 \ No newline at end of file From 45b8cf2d0def0043f27642193590a4e8922ed97c Mon Sep 17 00:00:00 2001 From: Yerim Moon Date: Fri, 13 Mar 2026 16:58:03 -0700 Subject: [PATCH 2/4] product of array except self solution --- product-of-array-except-self/yerim01.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 product-of-array-except-self/yerim01.py diff --git a/product-of-array-except-self/yerim01.py b/product-of-array-except-self/yerim01.py new file mode 100644 index 0000000000..15b3fdee83 --- /dev/null +++ b/product-of-array-except-self/yerim01.py @@ -0,0 +1,30 @@ +# Goal: Return an array answer that product of all elements except nums[i]. +# +# Approach: +# Use prefix&suffix arrays to store cumulative products +# - prefix: product of elements to the left of i +# - suffix: product of elements to the right of i +# Calculate the result[i] by multipying prefix[i] and suffix[i] +# +# Time Complexity: O(n) +# - We Iterate the array to compute prefix, suffix and result. +# Space Complexity: O(n) +# - We use extra arrays for prefix&suffix. +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + n = len(nums) + + prefix = [1] * n + suffix = [1] * n + result = [1] * n + + for i in range(1, n): + prefix[i] = prefix[i-1] * nums[i-1] + + for i in range(n-2, -1, -1): + suffix[i] = suffix[i+1] * nums[i+1] + + for i in range(len(nums)): + result[i] = prefix[i] * suffix[i] + + return result \ No newline at end of file From dfca88d83cdd6a4bf3375483da86b8f51989caff Mon Sep 17 00:00:00 2001 From: Yerim Moon Date: Fri, 13 Mar 2026 17:04:06 -0700 Subject: [PATCH 3/4] =?UTF-8?q?=EA=B0=9C=ED=96=89=EB=AC=B8=EC=9E=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- product-of-array-except-self/yerim01.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product-of-array-except-self/yerim01.py b/product-of-array-except-self/yerim01.py index 15b3fdee83..17f0ed4572 100644 --- a/product-of-array-except-self/yerim01.py +++ b/product-of-array-except-self/yerim01.py @@ -27,4 +27,4 @@ def productExceptSelf(self, nums: List[int]) -> List[int]: for i in range(len(nums)): result[i] = prefix[i] * suffix[i] - return result \ No newline at end of file + return result From c12a07f62d795a4b1296743b264be1c7814a7ea8 Mon Sep 17 00:00:00 2001 From: Yerim Moon Date: Fri, 13 Mar 2026 17:11:32 -0700 Subject: [PATCH 4/4] =?UTF-8?q?=EA=B0=9C=ED=96=89=EB=AC=B8=EC=9E=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/yerim01.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/climbing-stairs/yerim01.py b/climbing-stairs/yerim01.py index 5cee23f7ac..8030fa28e5 100644 --- a/climbing-stairs/yerim01.py +++ b/climbing-stairs/yerim01.py @@ -31,4 +31,4 @@ def climbStairs(self, n: int) -> int: prev1 = prev2 + prev1 prev2 = temp - return prev1 \ No newline at end of file + return prev1