From 5ce1a7cbf792309ffc993f180337ed3e3ae2ae38 Mon Sep 17 00:00:00 2001 From: JIHO CHOI Date: Thu, 3 Dec 2026 16:31:55 +0900 Subject: [PATCH 1/5] merge-two-sorted-lists solution Co-Authored-By: Claude Opus 5.5 --- merge-two-sorted-lists/wlghsp.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 merge-two-sorted-lists/wlghsp.py diff --git a/merge-two-sorted-lists/wlghsp.py b/merge-two-sorted-lists/wlghsp.py new file mode 100644 index 0000000000..c78d6a40b9 --- /dev/null +++ b/merge-two-sorted-lists/wlghsp.py @@ -0,0 +1,30 @@ +""" +N: list1의 노드 개수 +M: list2의 노드 개수 + +TC : O(N + M) +- 두 연결 리스트의 노드를 비교하면서 순차적으로 탐색한다 +- 최악의 경우 두 리스트의 전체 노드 개수에 비례하여 연산을 수행한다 +SC: O(1) +- 기존 노드를 재사용하여 연결하므로 별도의 리스트를 생성하지 않는다 +- dummy 노드와 current 포인터 등 상수 크기의 추가 공간만 사용한다 + +""" +class Solution: + def mergeTwoLists(self, list1: ListNode | None, list2: ListNode | None) -> ListNode | None: + dummy = ListNode() + current = dummy + + while list1 and list2: + if list1.val < list2.val: + current.next = list1 + list1.next = list1 + else: + current.next = list2 + list2.next = list2 + + current = current.next + + current.next = list1 if list1 else list2 + + return dummy.next From 3f493099ef6c71ff5d2f5560e84e3d511015c114 Mon Sep 17 00:00:00 2001 From: JIHO CHOI Date: Thu, 3 Dec 2026 16:31:55 +0900 Subject: [PATCH 2/5] maximum-depth-of-binary-tree solution Co-Authored-By: Claude Opus 5.5 --- maximum-depth-of-binary-tree/wlghsp.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 maximum-depth-of-binary-tree/wlghsp.py diff --git a/maximum-depth-of-binary-tree/wlghsp.py b/maximum-depth-of-binary-tree/wlghsp.py new file mode 100644 index 0000000000..5425a8536e --- /dev/null +++ b/maximum-depth-of-binary-tree/wlghsp.py @@ -0,0 +1,21 @@ +""" +N: 트리의 전체 노드 개수 +H: 트리의 높이 +TC : O(N) +- DFS를 통해 모든 노드를 한 번씩 방문한다 +- 각 노드에서 수행하는 연산은 O(1)이다. +- 따라서 전체 시간 복잡도는 O(N)이다. +SC: O(H) (최악의 경우 O(N)) +- 별도의 자료구조를 생성하지 않지만, 재귀 호출로 인해 Call Stack(호출 스택) 공간이 필요하다 + +""" +class Solution: + def maxDepth(self, root: TreeNode | None) -> int: + if not root: + return 0 + left = self.maxDepth(root.left) + + right = self.maxDepth(root.right) + + return max(left, right) + 1 + From ff337b1a741329b04a7c07330021fd5fc3bc3918 Mon Sep 17 00:00:00 2001 From: JIHO CHOI Date: Thu, 3 Dec 2026 16:31:55 +0900 Subject: [PATCH 3/5] find-minimum-in-rotated-sorted-array solution Co-Authored-By: Claude Opus 5.5 --- .../wlghsp.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/wlghsp.py diff --git a/find-minimum-in-rotated-sorted-array/wlghsp.py b/find-minimum-in-rotated-sorted-array/wlghsp.py new file mode 100644 index 0000000000..f00daacf56 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/wlghsp.py @@ -0,0 +1,25 @@ +""" +TC: O(log N) +SC: O(1) + +N: 배열 nums의 원소 개수 + +- 매 반복마다 탐색 범위를 절반으로 줄이므로 O(log N) +- 별도의 자료구조나 재귀 호출을 사용하지 않으므로 O(1) +""" +class Solution: + def findMin(self, nums: list[int]) -> int: + left, right = 0, len(nums) - 1 + + while left < right: + mid = (left + right) // 2 + + if nums[mid] > nums[right]: + left = mid + 1 + + else: + right = mid + + return nums[left] + + From 0b6b59ecf302df9fea0c1b7b94f5a4b68984d654 Mon Sep 17 00:00:00 2001 From: JIHO CHOI Date: Thu, 3 Dec 2026 20:53:34 +0900 Subject: [PATCH 4/5] word search solution --- word-search/wlghsp.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 word-search/wlghsp.py diff --git a/word-search/wlghsp.py b/word-search/wlghsp.py new file mode 100644 index 0000000000..e159df8663 --- /dev/null +++ b/word-search/wlghsp.py @@ -0,0 +1,47 @@ +""" +M: 행의 개수 +N: 열의 개수 +L: 단어의 길이 +TC: O(M * N * 3^L) +SC: O(L) + +""" +class Solution: + def exist(self, board: list[list[str]], word: str) -> bool: + M = len(board) + N = len(board[0]) + L = len(word) + + def dfs(x, y, index): + if index == L: + return True + + if not (0 <= x < M and 0 <= y < N): + return False + if board[x][y] != word[index]: + return False + + # 기존 문자 저장하고 방문 처리 + temp = board[x][y] + board[x][y] = '#' + + found = False + # found = (dfs(x + 1, y, index + 1) or dfs(x - 1, y, index + 1) + # or dfs(x, y + 1, index + 1) or dfs(x, y - 1, index + 1)) + for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: + nx, ny = x + dx, y + dy + if dfs(nx, ny, index + 1): + found = True + break + + # 기존 문자 복구 + board[x][y] = temp + + return found + + for i in range(M): + for j in range(N): + if dfs(i, j, 0): + return True + + return False From 0bc1cf0e737c09016ad98983d2376bf279e60948 Mon Sep 17 00:00:00 2001 From: JIHO CHOI Date: Fri, 4 Dec 2026 14:15:03 +0900 Subject: [PATCH 5/5] coin change solution --- coin-change/wlghsp.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 coin-change/wlghsp.py diff --git a/coin-change/wlghsp.py b/coin-change/wlghsp.py new file mode 100644 index 0000000000..ad4d7c9c99 --- /dev/null +++ b/coin-change/wlghsp.py @@ -0,0 +1,18 @@ +""" +N: amount +M: coins 개수 +TC: O(N * M) +SC: O(N) + +""" +class Solution: + def coinChange(self, coins: list[int], amount: int) -> int: + dp = [float('inf')] * (amount + 1) + dp[0] = 0 + + for i in range(1, amount + 1): + for coin in coins: + if i - coin >= 0: + dp[i] = min(dp[i], dp[i - coin] + 1) + + return dp[amount] if dp[amount] != float('inf') else - 1