Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions coin-change/freemjstudio.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가독성 좋게 잘 풀어주신 거 같습니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Hash Map / Hash Set
  • 설명: 금액에 대해 최소 개수의 동전으로 구성하는 문제로, 상태를 dp[n]로 정의하고 점화식을 이용해 최솟값을 구하는 전형적인 DP 패턴이다. 해시 맵/세트는 사용 가능한 동전 목록 관리에 보조적으로 사용될 수 있다.

📊 시간/공간 복잡도 분석

복잡도
Time O(amount * U)
Space O(amount)

피드백: usable_coins를 모아 두고 각 금액에 대해 이전 상태를 이용해 최소 개수를 갱신한다. amount의 크기와 사용 가능한 동전 수에 따라 시간 복잡도가 결정된다.

개선 제안: 고려해볼 만한 대안: 초기 금액이 큰 경우 BFS/동전 교환 문제의 표준 DP 방식으로 구현하면 직관적이며, 불필요한 루프를 줄여 상수 계수도 줄일 수 있습니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
if amount == 0:
return 0
INF = int(1e9)
# dp[n] 은 n 원을 만들기 위한 최소한의 동전 개수를 저장한다.
dp = [INF] * (amount + 1)
usable_coins = []
for coin in coins:
if coin == amount:
return 1
if coin < amount:
dp[coin] = 1 # dp[3] = 1
usable_coins.append(coin)

# dp 를 채워나가는 과정
for i in range(1, amount+1):
for coin in usable_coins:
if (i - coin) >= 0 and dp[i - coin] != INF:
dp[i] = min(dp[i - coin] + 1, dp[i])

return -1 if dp[amount] == INF else dp[amount]
19 changes: 19 additions & 0 deletions find-minimum-in-rotated-sorted-array/freemjstudio.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search
  • 설명: 정렬된 배열이 회전되었을 때 최소값을 이분 탐색으로 찾는 문제로, 좌우를 반으로 나눠 조건에 따라 탐색 범위를 좁히는 이분 탐색 패턴이 사용됩니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(log n)
Space O(1)

피드백: 정렬 상태의 일부 특성을 이용해 중앙값과 끝 값 비교로 범위를 절반으로 축소한다.

개선 제안: 현재 구현은 min_value 초기화가 상수로 잡혀 있지만, 일반적으로 nums[mid]와 nums[right] 비교를 통해 더 명확하게 구현 가능하며, 중복 원소 처리까지 고려하면 안전합니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def findMin(self, nums: List[int]) -> int:
min_value = 5000
# O(log n) 이므로 binary search
if len(nums) == 1:
return nums[0]
left = 0
right = len(nums) - 1

while left <= right:
mid = (left + right) // 2
min_value = min(nums[mid], min_value)

Comment thread
freemjstudio marked this conversation as resolved.
if nums[mid] > nums[right]:
left = mid + 1
else:
right = mid - 1

return min_value
14 changes: 14 additions & 0 deletions maximum-depth-of-binary-tree/freemjstudio.py
Comment thread
freemjstudio marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Binary Search
  • 설명: 자식 노드로 재귀적으로 탐색하며 트리의 깊이를 계산하는 방식으로 DFS 패턴에 해당합니다. 재귀를 통해 좌우 서브트리의 최대 깊이를 구하고 1을 더해 최댓값을 반환합니다. Binary Search는 트리 구조의 분할 탐색으로 간주될 수 있지만 주된 패턴은 DFS입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(h)

피드백: 자식 노드를 재귀적으로 탐색해 좌우 깊이의 최댓값에 +1을 더한다. 스택 깊이는 트리의 높이에 비례한다.

개선 제안: 꼭 재귀 대신 명시적 스택으로 구현해 시스템 스택 오버플로를 피하는 방법도 있음.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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 maxDepth(self, root: Optional[TreeNode]) -> int:
if root is None:
return 0

left = self.maxDepth(root.left)
right = self.maxDepth(root.right)
return max(left, right) + 1
24 changes: 24 additions & 0 deletions merge-two-sorted-lists/freemjstudio.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Merge Type (not in list), Linked List
  • 설명: 두 개의 정렬된 연결 리스트를 순회하며 포인터 두 개로 작은 값을 차례로 연결 리스트에 붙이는 전형적인 Two Pointers 패턴이며, 연결 리스트를 다루는 방식이 포함되어 있습니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n + m)
Space O(1)

피드백: 두 포인터를 이용해 차례대로 노드를 연결 리스트에 붙이고 남은 노드를 뒤에 연결한다.

개선 제안: 재귀 방식으로도 구현 가능하나 스택 깊이가 커질 수 있어 현재의 반복 구현이 안정적이다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
dummy = ListNode()
merged_list = dummy
Comment thread
freemjstudio marked this conversation as resolved.

while list1 is not None and list2 is not None:
if list1.val <= list2.val:
merged_list.next = list1
list1 = list1.next
else:
merged_list.next = list2
list2 = list2.next
# merged_list 포인터를 한칸 이동시켜서 다음 노드 붙일 준비
merged_list = merged_list.next

# 남아 있는 노드 붙이기
merged_list.next = list1 if list1 is not None else list2
Comment thread
freemjstudio marked this conversation as resolved.

return dummy.next
Loading