Skip to content

[ICE0208] WEEK 10 Solutions - #2843

Merged
ICE0208 merged 3 commits into
DaleStudy:mainfrom
ICE0208:week10
Aug 29, 2026
Merged

[ICE0208] WEEK 10 Solutions#2843
ICE0208 merged 3 commits into
DaleStudy:mainfrom
ICE0208:week10

Conversation

@ICE0208

@ICE0208 ICE0208 commented Aug 29, 2026

Copy link
Copy Markdown
Member

답안 제출 문제

작성자 체크 리스트

  • 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.

🏷️ 알고리즘 패턴 분석

course-schedule/ICE0208.java
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

class Solution {
    public boolean canFinish(int numCourses, int[][] prerequisites) {
        int[] indegree = new int[numCourses];

        List<List<Integer>> graph = new ArrayList<>();
        for (int course = 0; course < numCourses; course++) {
            graph.add(new ArrayList<>());
        }

        for (int[] prerequisite : prerequisites) {
            int course = prerequisite[0];
            int prerequisiteCourse = prerequisite[1];

            graph.get(prerequisiteCourse).add(course);
            indegree[course]++;
        }

        Queue<Integer> queue = new ArrayDeque<>();

        for (int course = 0; course < numCourses; course++) {
            if (indegree[course] == 0) {
                queue.offer(course);
            }
        }

        int completedCourses = 0;

        while (!queue.isEmpty()) {
            int course = queue.poll();
            completedCourses++;

            for (int nextCourse : graph.get(course)) {
                indegree[nextCourse]--;

                if (indegree[nextCourse] == 0) {
                    queue.offer(nextCourse);
                }
            }
        }

        return completedCourses == numCourses;
    }
}
  • 패턴: BFS, Topological Sort
  • 설명: 입력 의존성 그래프를 만들고 위상 정렬 방식으로 처리하며, 큐를 이용해 차수 0 노드를 순차적으로 제거하는 구조로 패키지 의존성 해결에 적합한 BFS/위상 정렬 패턴이 사용됩니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(N + P)
Space O(N + P)

피드백: 그래프를 인접 리스트로 구성하고 진입 차수 배열로 위상정렬을 수행한다. 모든 정점을 방문하면 사이클이 없음을 뜻한다.

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

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

@dalestudy

dalestudy Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

📊 ICE0208 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
course-schedule Medium ✅ 의도한 유형
invert-binary-tree Easy ✅ 의도한 유형
search-in-rotated-sorted-array Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 1,181 111 1,292 $0.000103

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.

🏷️ 알고리즘 패턴 분석

invert-binary-tree/ICE0208.java
class Solution {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }

        invertTree(root.left);
        invertTree(root.right);

        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;

        return root;
    }
}
  • 패턴: Recursive, Binary Search, DFS
  • 설명: 루트 트리를 재귀적으로 방문하여 좌우 자식을 교환하는 방식으로 이진 트리를 뒤집는다. 재귀 탐색(깊이 우선 탐색) 패턴과 단순한 재귀 응용으로 분류된다.

📊 시간/공간 복잡도 분석

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

피드백: 트리의 각 노드를 한 번씩 방문하고 자식 노드를 교환한다. 최악의 경우 깊이는 트리의 높이 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.

🏷️ 알고리즘 패턴 분석

search-in-rotated-sorted-array/ICE0208.java
class Solution {
    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;

        while (left <= right) {
            int mid = left + (right - left) / 2;

            if (nums[mid] == target) {
                return mid;
            }

            // 왼쪽 절반이 정렬되어 있는 경우
            if (nums[left] <= nums[mid]) {
                if (nums[left] <= target && target < nums[mid]) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }

            // 오른쪽 절반이 정렬되어 있는 경우
            else {
                if (nums[mid] < target && target <= nums[right]) {
                    left = mid + 1;
                } else {
                    right = mid - 1;
                }
            }
        }

        return -1;
    }
}
  • 패턴: Binary Search
  • 설명: 로테이트된 정렬 배열에서 목표 값을 이진 탐색으로 찾되, 어느 쪽 절반이 정렬되었는지 판단하고 그에 맞춰 범위를 절단하는 패턴으로 구현됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 왼쪽 또는 오른쪽 중 어느 절반이 정렬되었는지 판별하고, 정렬된 절반에서 타깃이 위치하는지 확인한 후 범위를 축소한다.

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

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

@parkhojeong
parkhojeong self-requested a review August 29, 2026 12:38

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

간결하게 풀어주셔서 이해가 잘 되었습니다. 수고하셨습니다!

public boolean canFinish(int numCourses, int[][] prerequisites) {
int[] indegree = new int[numCourses];

List<List<Integer>> graph = new ArrayList<>();

@parkhojeong parkhojeong Aug 29, 2026

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.

graph 변수에 어떤 값이 들어가는지 관련 코드를 찾아 보고나서 이해가 되었던 거 같습니다. prerequisiteCourse 에 대한 nextCourses가 담기는데 의미를 나타내도록 네이밍을 하면 더 좋을 거 같습니다.

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.

graph와 indegree를 초기화 하는 부분과 실제 판단하는 부분으로 크게 나뉘는데 어디까지가 초기화고 어디부터가 실제 판단 로직인지 바로 알기는 어려웠던 거 같습니다. 초기화하는 부분 정도만 함수로 빼거나 초기화/판단 로직 구분이 되도록 주석으로 나타내면 어떨까 싶네요~

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

그럴 수 있겠네요! 좋은 피드백 감사합니다 👍

@ICE0208
ICE0208 merged commit b37c706 into DaleStudy:main Aug 29, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 8기 Aug 29, 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