Skip to content

[dahyeong-yun] WEEK 12 Solutions - #2859

Open
dahyeong-yun wants to merge 3 commits into
DaleStudy:mainfrom
dahyeong-yun:week-12
Open

[dahyeong-yun] WEEK 12 Solutions#2859
dahyeong-yun wants to merge 3 commits into
DaleStudy:mainfrom
dahyeong-yun:week-12

Conversation

@dahyeong-yun

@dahyeong-yun dahyeong-yun 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/dahyeong-yun.java
/**
 * TC : O(n log n)
 *   - intervals 배열의 길이 n 을 최초 정렬 하므로 O(n log n)
 *   - 이후 for loop 는 O(n)
 * SC : O(1)
 *   - 별도 유의미한 공간 할당은 없음
 */
class Solution {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, (a, b) -> Integer.compare(a[1], b[1]));

        int count = 1;
        int beforeEnd = intervals[0][1];

        for (int i = 1; i < intervals.length; i++) {
            if (intervals[i][0] >= beforeEnd) {
                count++;
                beforeEnd = intervals[i][1];
            }
        }
        return intervals.length - count;
    }
}
  • 패턴: Greedy, Sort
  • 설명: 간격들의 끝점 기준으로 가장 많은 비겹치는 구간을 남기려는 탐욕적 접근이며, 끝점을 기준으로 정렬 후 가능한 한 빨리 끝나는 구간을 선택하는 전형적 그리디 패턴이다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n log n) O(n log n)
Space O(1) O(1)

피드백: 종료점을 기준으로 정렬하고, 이전 종료점 이후의 구간만 남겨두어 중복을 제거합니다.

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

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.

🏷️ 알고리즘 패턴 분석

remove-nth-node-from-end-of-list/dahyeong-yun.java
/**
 * TC: O(n)
 *   - ListNode의 길이 n 만큰 순회하므로 O(n)
 * SC: O(n)
 *   - ListNode의 길이 n 만큼 ArrayList 할당하므로 O(n)
 */
class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        List<ListNode> list = new ArrayList<>();
        ListNode cursor = head.next;
        list.add(head);

        while (cursor != null) {
            list.add(cursor);
            cursor = cursor.next;
        }

        int sz = list.size();
        int deleteTarget = list.size() - n;
        if (deleteTarget < 0)
            return null;

        if (deleteTarget - 1 >= 0 && deleteTarget <= sz - 2) {
            list.get(deleteTarget - 1).next = list.get(deleteTarget + 1);
        } else if(deleteTarget == 0) {
            head = head.next;
        } else {
            list.get(deleteTarget - 1).next = null;
        }
        return head;
    }
}
  • 패턴: Two Pointers, Hash Map / Hash Set
  • 설명: 리스트를 한 번 순회하며 인덱스를 이용해 뒤에서 제거할 노드를 찾고, 미리 수집한 노드 참조를 이용해 연결을 끊는 방식으로 문제를 해결하므로 두 포인터/인덱스 접근 패턴과 배열 인덱스를 이용한 참조 배열 패턴이 혼합된 형태로 보입니다.

📊 시간/공간 복잡도 분석

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

피드백: 리스트를 배열에 저장하므로 추가 공간이 필요하지만 구현은 직관적입니다.

개선 제안: 공간 복잡도를 줄이려면 더블 포인터(스피닝) 기법으로 O(1) 공간으로 개선할 수 있습니다.

@dalestudy

dalestudy Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

📊 dahyeong-yun 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
non-overlapping-intervals Medium ✅ 의도한 유형
remove-nth-node-from-end-of-list Medium ⚠️ 유형 불일치
same-tree Easy ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 1,225 143 1,368 $0.000118

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/dahyeong-yun.java
/**
 * TC : O(n)
 *   - TreeNode의 노드 수 n 만큼 순회하므로 O(n)
 * SC : O(n)
 *   - TreeNode의 노드 높이 h 만큼 콜스택이 쌓이고, 편향 트리의 경우 O(n) 까지 공간이 필요
 */
class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        // p와 q 둘다 null 인가?
        if(p == null && q == null) {
            return true;
        } else if(p == null || q == null) { // 하나만 null 인가
            return false;
        } else if(p.val != q.val) {
            return false;
        } else {
            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }
}
  • 패턴: Depth-First Search, Binary Search
  • 설명: 같은 트리를 재귀적으로 비교하는 방식은 DFS의 전형적 패턴이며, 두 노드를 순회하며 좌우 자식까지 확인한다. 이 문제는 트리의 각 노드를 방문하는 재귀적 탐색으로 해결된다.

📊 시간/공간 복잡도 분석

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

피드백: 최악의 경우 편향 트리에서 스택 깊이가 증가하므로 공간 복잡도는 트리의 높이와 같습니다.

개선 제안: 추가적인 최적화는 필요 없으며, 트리의 구조에 따른 일반적인 재귀 풀이에 해당합니다.

@dahyeong-yun dahyeong-yun moved this from Solving to In Review in 리트코드 스터디 8기 Sep 12, 2026
@okyungjin
okyungjin self-requested a review September 12, 2026 09:32

@okyungjin okyungjin 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.

고생하셨습니다 : )

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.

end 기준으로 정렬한 후에 남길 구간의 개수를 세고, 전체 구간의 개수에서 빼주는 로직으로 이해했습니다.
저는 제거할 구간의 개수를 세도록 구현했는데 이 점이 다르네요.

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.

달레 스터디 리뷰에도 있는데 공간 복잡도 O(1)로 개선할 수 있는 것 같습니다 ㅎㅎ
저번 주 문제 중에 비슷한 방법이 있던 것 같아요

개선 제안: 공간 복잡도를 줄이려면 더블 포인터(스피닝) 기법으로 O(1) 공간으로 개선할 수 있습니다.

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.

재귀 사용해서 DFS로 깔끔하게 풀어주셨네요.
혹시 DFS 풀이를 선택하신 이유가 있을까요?

@dahyeong-yun dahyeong-yun changed the title dahyeong-yun] WEEK 12 Solutions [dahyeong-yun] WEEK 12 Solutions Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants