Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions find-minimum-in-rotated-sorted-array/dolphinflow86.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)

피드백: 중간 인덱스(pivot)와 끝 원소를 비교해 왼쪽이 정렬되었는지 여부를 판단하고, 범위를 절반으로 축소한다.

개선 제안: 현재 구현이 적절해 보입니다.

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

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.

혹시 pivot을 (right + left) // 2 가 아닌 left + (right - left) // 2 로 하신 이유가 있으실까요?

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 1) Use binary search to halves to search range. Each iteration,
# compare with nums[pivot] and nums[right] to see which side has a smaller range.
# Firstly I compare nums[left] with nums[right] so I got the wrong results but end up with the right solution.
# TC: O(logN) where N is the length of the nums array
# SC: O(1)

class Solution:
def findMin(self, nums: List[int]) -> int:
n = len(nums)
left = 0
right = n-1

while left < right:
pivot = left + (right - left) // 2
if nums[pivot] < nums[right]:
right = pivot
else:
left = pivot + 1

return nums[right]
20 changes: 20 additions & 0 deletions maximum-depth-of-binary-tree/dolphinflow86.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Binary Search
  • 설명: 주로 트리를 DFS로 탐색하며 각 서브트리의 깊이를 계산합니다. 재귀를 이용한 탐색으로 전체 노드를 순회하고 트리의 높이를 구하는 전형적인 DFS 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n)
Space O(H) O(h)

피드백: 재귀적으로 각 서브트리의 깊이를 계산하고 최댓값을 상향 전달한다.

개선 제안: 현재 구현이 적절해 보입니다.

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 패러미터 주지 않고 maxDepth 만으로도 구현 가능하세요! 스스로 재귀해서 하면 코드도 엄청 줄일수 있어요, 성능도 같고요

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 1) Use DFS to traverse down to the leaf node. Keep track of depth and return each node's maximum depth of each subtree to the parent node.
# TC: O(N) where N is the number of node in the binary tree
# SC: O(H) where H is the height of the binary tree
# 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 dfs(self, node: Optional[TreeNode], depth: int) -> int:
if not node:
return depth

left = self.dfs(node.left, depth + 1)
right = self.dfs(node.right, depth + 1)
return max(left, right)

def maxDepth(self, root: Optional[TreeNode]) -> int:
return self.dfs(root, 0)
27 changes: 27 additions & 0 deletions merge-two-sorted-lists/dolphinflow86.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
  • 설명: 두 연결 리스트의 포인터를 동시에 따라가며 더 작은 값을 선택해 새로운 리스트를 구성하는 방식으로, 두 포인터를 이동시키는 패턴이 핵심입니다.

📊 시간/공간 복잡도 분석

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

피드백: 두 리스트를 순회하며 각 노드를 차례로 이어붙이고 남은 부분을 연결한다.

개선 제안: 현재 구현이 적절해 보입니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 1) Use a dummy node and connect the smaller node to the merged list while iterating through both lists.
# TC: O(N + M) where N is the length of list1 and M is the length of list2.
# SC: O(1)
#
# 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()
curr = dummy

while list1 and list2:
if list1.val < list2.val:
curr.next = list1
list1 = list1.next
else:
curr.next = list2
list2 = list2.next
curr = curr.next

curr.next = list1 if list1 else list2

return dummy.next
Loading