From 35df9c2559de592673ecaebb1144f089be4b0ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=8F=99=ED=95=B4?= Date: Wed, 19 Nov 2025 21:08:32 +0900 Subject: [PATCH 1/3] valid-anagram solution --- valid-anagram/Donghae0230.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 valid-anagram/Donghae0230.py diff --git a/valid-anagram/Donghae0230.py b/valid-anagram/Donghae0230.py new file mode 100644 index 0000000000..9bc78810f7 --- /dev/null +++ b/valid-anagram/Donghae0230.py @@ -0,0 +1,13 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + s_list = sorted(list(s)) + t_list = sorted(list(t)) + # 1. 두 단어의 길이가 다른 경우 false 반환 + if len(s_list) != len(t_list): + return False + else: + # 2. 각 알파벳의 순서가 일치하지 않는 경우 false 반환 + for i in range(0, len(s_list)): + if s_list[i] != t_list[i]: + return False + return True From 10493754e1e78dd83bef2e9886d4b41a1d432135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=8F=99=ED=95=B4?= Date: Sat, 22 Nov 2025 15:21:32 +0900 Subject: [PATCH 2/3] =?UTF-8?q?2=EC=A3=BC=EC=B0=A8=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/Donghae0230.py | 21 ++++++++++ product-of-array-except-self/Donghae0230.py | 43 +++++++++++++++++++++ valid-anagram/Donghae0230.py | 2 + 3 files changed, 66 insertions(+) create mode 100644 climbing-stairs/Donghae0230.py create mode 100644 product-of-array-except-self/Donghae0230.py diff --git a/climbing-stairs/Donghae0230.py b/climbing-stairs/Donghae0230.py new file mode 100644 index 0000000000..ab43068d4a --- /dev/null +++ b/climbing-stairs/Donghae0230.py @@ -0,0 +1,21 @@ +# 1스텝 또는 2스텝으로 n개의 계단을 오르는 방법 경우의 수 구하기 +# 1계단: 1 +# 2계단: 2 , 1 + 1 +# 3계단: 2 + 1, 1+1+1, 1+2 +# 4계단: 2+2, 1+1+1+1, 2+1+1, 1+2+1, 1+1+2 +# -> 방법: step_n = step_(n-1) + step_(n-2) +# 시간 복잡도: O(n), while문 사용 +# 공간 복잡도: O(n), 길이 n인 result 리스트 생성 +class Solution: + def climbStairs(self, n: int) -> int: + if n == 1: + return 1 + elif n == 2: + return 2 + else: + result = [1, 2] + i = 2 + while i < n: + result.append(result[i-1] + result[i-2]) + i += 1 + return result[-1] \ No newline at end of file diff --git a/product-of-array-except-self/Donghae0230.py b/product-of-array-except-self/Donghae0230.py new file mode 100644 index 0000000000..d7b93aac21 --- /dev/null +++ b/product-of-array-except-self/Donghae0230.py @@ -0,0 +1,43 @@ +# 2차 시도: 왼쪽 누적 곱 * 오른쪽 누적 곱 +# 시간 복잡도: O(n), for문 사용 +# 공간 복잡도: O(n), 길이 n인 리스트 prefix, suffix, result 생성 +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + # 왼쪽 누적 곱 리스트 생성 + prefix = [nums[0]] + for i in range(1, len(nums)-1): + tmp = nums[i] + prefix.append(prefix[i-1] * nums[i]) + + nums.reverse() + # 오른쪽 누적 곱 리스트 생성 + suffix = [nums[0]] + for i in range(1, len(nums)-1): + tmp = nums[i] + suffix.append(suffix[i-1] * nums[i]) + + # result[0] = suffix[2] + # result[1] = suffix[1] * prefix[0] + # result[2] = suffix[0] * prefix[1] + # result[3] = prefix[2] + result = [0 for i in range(0, len(nums))] + result[0] = suffix[-1] + result[-1] = prefix[-1] + for i in range(1, len(nums)-1): + result[i] = suffix[len(nums)-2-i] * prefix[i-1] + return result + + +# 1차 시도: 이중 for문 사용 +# 시간 복잡도: O(n^2)으로 실패 +# class Solution: +# def productExceptSelf(self, nums: List[int]) -> List[int]: +# result = [] +# for i in range(0, len(nums)): +# tmp = 1 +# for j in range(0, len(nums)): +# if i == j: +# continue +# tmp *= nums[j] +# result.append(tmp) +# return result \ No newline at end of file diff --git a/valid-anagram/Donghae0230.py b/valid-anagram/Donghae0230.py index 9bc78810f7..ab217a830e 100644 --- a/valid-anagram/Donghae0230.py +++ b/valid-anagram/Donghae0230.py @@ -1,3 +1,5 @@ +# 시간 복잡도: O(n), for문 사용 +# 공간 복잡도: O(n), 길이 n인 s_list, t_list 생성 class Solution: def isAnagram(self, s: str, t: str) -> bool: s_list = sorted(list(s)) From a8c940acf2bf76060602cec3c6d9e7db72202f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=8F=99=ED=95=B4?= Date: Sat, 22 Nov 2025 15:23:05 +0900 Subject: [PATCH 3/3] line lint --- climbing-stairs/Donghae0230.py | 2 +- product-of-array-except-self/Donghae0230.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/climbing-stairs/Donghae0230.py b/climbing-stairs/Donghae0230.py index ab43068d4a..20d2b08236 100644 --- a/climbing-stairs/Donghae0230.py +++ b/climbing-stairs/Donghae0230.py @@ -18,4 +18,4 @@ def climbStairs(self, n: int) -> int: while i < n: result.append(result[i-1] + result[i-2]) i += 1 - return result[-1] \ No newline at end of file + return result[-1] diff --git a/product-of-array-except-self/Donghae0230.py b/product-of-array-except-self/Donghae0230.py index d7b93aac21..81d745d1ff 100644 --- a/product-of-array-except-self/Donghae0230.py +++ b/product-of-array-except-self/Donghae0230.py @@ -40,4 +40,4 @@ def productExceptSelf(self, nums: List[int]) -> List[int]: # continue # tmp *= nums[j] # result.append(tmp) -# return result \ No newline at end of file +# return result