[okyungjin] WEEK 12 Solutions - #2860
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
non-overlapping-intervals/okyungjin.py
"""
https://leetcode.com/problems/non-overlapping-intervals/
Time: O(N)
Space: O(1)
"""
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
# 1. end 오름차순 intervals 정렬
intervals.sort(key=lambda x: x[1])
# remove count
count = 0
last_end = float('-inf')
for start, end in intervals:
if start >= last_end: # 구간 안 겹침
last_end = end
else: # 구간 겹침
count += 1
return count- 패턴: Greedy, Two Pointers
- 설명: 최소 제거 수를 구하기 위해 종료시간 기준으로 오름차순 정렬하고, 현재 구간의 시작과 이전 종료를 비교하여 겹침 여부를 판단하는 방식으로 최적해를 찾으므로 Greedy 패턴에 속하며 투 포인터처럼 앞쪽 포인터(last_end)와 현재 포인터를 사용해 유효 구간을 검사합니다.
📊 시간/공간 복잡도 분석
| 복잡도 | |
|---|---|
| Time | O(n log n) |
| Space | O(1) |
피드백: 끝점을 기준으로 정렬한 뒤, 현재 구간의 시작이 last_end 이상이면 겹치지 않는 구간으로 간주하고, 그렇지 않으면 제거 카운트를 증가시키는 방식이다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
Contributor
📊 okyungjin 님의 학습 현황이번 주 제출 문제
누적 학습 요약
문제 풀이 현황
🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다. 🔢 API 사용량 (gpt-5-nano)
|
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
same-tree/okyungjin.py
"""
https://leetcode.com/problems/same-tree/description/
N: min(p노드수, q노드수)
Time: O(N)
Space: O(N)
"""
# 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 isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
queue = deque([(p, q)])
while queue:
node_p, node_q = queue.popleft()
if not node_p and not node_q:
continue
elif node_p and node_q:
if node_p.val == node_q.val:
queue.append((node_p.left, node_q.left))
queue.append((node_p.right, node_q.right))
else:
return False
else:
return False
return True- 패턴: Breadth-First Search, Hash Map / Hash Set
- 설명: 두 트리의 같은 위치 노드를 한 쌍으로 큐에 담아 레벨 단위로 비교하는 BFS 방식으로 모든 노드를 순회합니다. 각 노드의 값과 존재 여부를 비교해 동일하면 자식 노드를 큐에 추가합니다.
📊 시간/공간 복잡도 분석
| 복잡도 | |
|---|---|
| Time | O(n) |
| Space | O(n) |
피드백: 큐에 노드를 쌍으로 담아 동시 탐색하며 각 위치의 값과 구조를 검사한다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
non-overlapping-intervals/okyungjin.py
"""
https://leetcode.com/problems/non-overlapping-intervals/
Time: O(N log N), intervals 정렬
Space: O(1)
"""
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
# end 오름차순 intervals 정렬
intervals.sort(key=lambda x: x[1])
# remove count
count = 0
last_end = float('-inf')
for start, end in intervals:
if start >= last_end: # 구간 안 겹침
last_end = end
else: # 구간 겹침
count += 1
return count- 패턴: Greedy, Two Pointers
- 설명: 끝 점 오름차순 정렬 후 현재 구간과 비교하여 겹치면 제거(카운트)하는 방식으로 최적 해를 찾으므로 그리디 패턴이며, 포인터를 이용한 탐색 흐름도 존재합니다.
📊 시간/공간 복잡도 분석
| 복잡도 | |
|---|---|
| Time | O(n log n) |
| Space | O(1) |
피드백: 종료점으로 정렬한 뒤 현재 구간과의 겹침 여부를 판단하고 겹치면 제거 카운트를 증가시킨다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!