Skip to content

[okyungjin] WEEK 12 Solutions - #2860

Merged
okyungjin merged 3 commits into
DaleStudy:mainfrom
okyungjin:main
Sep 12, 2026
Merged

[okyungjin] WEEK 12 Solutions#2860
okyungjin merged 3 commits into
DaleStudy:mainfrom
okyungjin:main

Conversation

@okyungjin

@okyungjin okyungjin commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

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.

🏷️ 알고리즘 패턴 분석

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 이상이면 겹치지 않는 구간으로 간주하고, 그렇지 않으면 제거 카운트를 증가시키는 방식이다.

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

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

@dalestudy

dalestudy Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

📊 okyungjin 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
non-overlapping-intervals Medium ✅ 의도한 유형
same-tree Easy ✅ 의도한 유형

누적 학습 요약

  • 풀이한 문제: 31 / 75개
  • 이번 주 유형 일치율: 100% (2문제 중 2문제 일치)

문제 풀이 현황

카테고리 진행도 완료
Array ■■■■■□□ 7 / 10 (Medium 4, Easy 3)
String ■■■■□□□ 6 / 10 (Medium 3, Easy 3)
Dynamic Programming ■■■■□□□ 6 / 11 (Easy 1, Medium 5)
Linked List ■■■■□□□ 3 / 6 (Easy 2, Medium 1)
Binary ■■■□□□□ 2 / 5 (Easy 2)
Heap ■■□□□□□ 1 / 3 (Medium 1)
Matrix ■■□□□□□ 1 / 4 (Medium 1)
Tree ■■□□□□□ 3 / 14 (Medium 2, Easy 1)
Interval ■□□□□□□ 1 / 5 (Medium 1)
Graph ■□□□□□□ 1 / 8 (Medium 1)

🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다.

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 774 93 867 $0.000076
2 777 79 856 $0.000070
합계 1,551 172 1,723 $0.000146

Comment thread same-tree/okyungjin.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.

🏷️ 알고리즘 패턴 분석

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)

피드백: 큐에 노드를 쌍으로 담아 동시 탐색하며 각 위치의 값과 구조를 검사한다.

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

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

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.

🏷️ 알고리즘 패턴 분석

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)

피드백: 종료점으로 정렬한 뒤 현재 구간과의 겹침 여부를 판단하고 겹치면 제거 카운트를 증가시킨다.

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

@parkhojeong parkhojeong left a comment

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.

수고 많으셨습니다!

@okyungjin
okyungjin merged commit fa2c562 into DaleStudy:main Sep 12, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 8기 Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

2 participants