From b05f8bb9e1ed898539d5e560380f39f93816b7c2 Mon Sep 17 00:00:00 2001 From: 8804 <8804who@naver.com> Date: Mon, 17 Nov 2025 22:48:54 +0900 Subject: [PATCH 1/4] Week 2 --- climbing-stairs/8804who.py | 9 +++++++++ product-of-array-except-self/8804who.py | 17 +++++++++++++++++ valid-anagram/8804who.py | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 climbing-stairs/8804who.py create mode 100644 product-of-array-except-self/8804who.py create mode 100644 valid-anagram/8804who.py diff --git a/climbing-stairs/8804who.py b/climbing-stairs/8804who.py new file mode 100644 index 0000000000..b0ebd47619 --- /dev/null +++ b/climbing-stairs/8804who.py @@ -0,0 +1,9 @@ +class Solution: + def climbStairs(self, n: int) -> int: + dp = [1] * (n+1) + + for i in range(2, n+1): + dp[i] = dp[i-1]+dp[i-2] + + return dp[n] + diff --git a/product-of-array-except-self/8804who.py b/product-of-array-except-self/8804who.py new file mode 100644 index 0000000000..5f157f03f4 --- /dev/null +++ b/product-of-array-except-self/8804who.py @@ -0,0 +1,17 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + total_product = 1 + + for num in nums: + if num != 0: + total_product *= num + + if nums.count(0) == 1: + return [0 if num != 0 else total_product for num in nums] + elif nums.count(0) > 1: + return [0 for _ in range(len(nums))] + else: + return [total_product//num for num in nums] + + + diff --git a/valid-anagram/8804who.py b/valid-anagram/8804who.py new file mode 100644 index 0000000000..9e304a8d91 --- /dev/null +++ b/valid-anagram/8804who.py @@ -0,0 +1,5 @@ +from collections import Counter +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + return Counter(s) == Counter(t) + From 2c28ffef67907669b63251275e132055eee3611d Mon Sep 17 00:00:00 2001 From: 8804 <8804who@naver.com> Date: Mon, 17 Nov 2025 23:53:24 +0900 Subject: [PATCH 2/4] Week 2 --- 3sum/8804who.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 3sum/8804who.py diff --git a/3sum/8804who.py b/3sum/8804who.py new file mode 100644 index 0000000000..63208ed231 --- /dev/null +++ b/3sum/8804who.py @@ -0,0 +1,17 @@ +class Solution: + def threeSum(self, nums: List[int]) -> List[List[int]]: + temp = {} + answer = {} + nums.sort() + for i in range(len(nums)): + for j in range(i+1, len(nums)): + if -(nums[i]+nums[j]) in temp: + ans = str(nums[i])+','+str(nums[j]) + answer[ans] = 1 + temp[nums[i]] = 1 + temp_ans = [] + for ans in answer.keys(): + s1, s2 = ans.split(',') + temp_ans.append([int(s1), int(s2), -(int(s1)+int(s2))]) + return temp_ans + From e4b1adb8d256e5d7f57f8b673f824961995f800e Mon Sep 17 00:00:00 2001 From: 8804 <8804who@naver.com> Date: Wed, 19 Nov 2025 22:24:58 +0900 Subject: [PATCH 3/4] Week 2 --- validate-binary-search-tree/8804who.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 validate-binary-search-tree/8804who.py diff --git a/validate-binary-search-tree/8804who.py b/validate-binary-search-tree/8804who.py new file mode 100644 index 0000000000..7e54be79b6 --- /dev/null +++ b/validate-binary-search-tree/8804who.py @@ -0,0 +1,16 @@ +# 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: + def dfs(node, min_num, max_num): + if not node: + return True + if max_num <= node.val or node.val <= min_num: + return False + return dfs(node.left, min_num, node.val) and dfs(node.right, node.val, max_num) + return dfs(root, float("-inf"), float("inf")) + From 4767b91a39988eedb837a2b63f85efcb6cd6bd40 Mon Sep 17 00:00:00 2001 From: 8804 <8804who@naver.com> Date: Fri, 21 Nov 2025 23:55:15 +0900 Subject: [PATCH 4/4] Week 2 --- product-of-array-except-self/8804who.py | 33 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/product-of-array-except-self/8804who.py b/product-of-array-except-self/8804who.py index 5f157f03f4..3a32c7b765 100644 --- a/product-of-array-except-self/8804who.py +++ b/product-of-array-except-self/8804who.py @@ -1,17 +1,26 @@ class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: - total_product = 1 + answer = [] - for num in nums: - if num != 0: - total_product *= num - - if nums.count(0) == 1: - return [0 if num != 0 else total_product for num in nums] - elif nums.count(0) > 1: - return [0 for _ in range(len(nums))] - else: - return [total_product//num for num in nums] - + product1 = [0] * len(nums) + product2 = [0] * len(nums) + + product1[0] = nums[0] + + for i in range(1, len(nums)): + product1[i] = product1[i-1]*nums[i] + product2[-1] = nums[-1] + for i in range(len(nums)-2, -1, -1): + product2[i] = product2[i+1] * nums[i] + + for i in range(len(nums)): + if i == 0: + answer.append(product2[1]) + elif i == len(nums)-1: + answer.append(product1[-2]) + else: + answer.append(product1[i-1]*product2[i+1]) + return answer +