Skip to content

[ICE0208] WEEK 09 Solutions - #2833

Merged
parkhojeong merged 2 commits into
DaleStudy:mainfrom
ICE0208:week09
Aug 22, 2026
Merged

[ICE0208] WEEK 09 Solutions#2833
parkhojeong merged 2 commits into
DaleStudy:mainfrom
ICE0208:week09

Conversation

@ICE0208

@ICE0208 ICE0208 commented Aug 22, 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.

🏷️ 알고리즘 패턴 분석

linked-list-cycle/ICE0208.java
class Solution {
    public boolean hasCycle(ListNode head) {
        ListNode slow = head;
        ListNode fast = head;

        // fast가 끝에 도달하면 cycle이 없다.
        while (fast != null && fast.next != null) {
            slow = slow.next;           // 한 칸 이동
            fast = fast.next.next;      // 두 칸 이동

            // cycle이 있다면 두 포인터는 결국 같은 노드에서 만난다.
            if (slow == fast) {
                return true;
            }
        }

        return false;
    }
}
  • 패턴: Fast & Slow Pointers, Two Pointers
  • 설명: 이 코드는 두 포인터(slow, fast)를 서로 다른 속도로 순환하며 사이클 여부를 판별하는 방식으로, Fast & Slow Pointers 패턴의 전형적인 구현입니다. 두 포인터가 서로 만나면 사이클 존재를 확인합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space 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.

🏷️ 알고리즘 패턴 분석

pacific-atlantic-water-flow/ICE0208.java
import java.util.ArrayList;
import java.util.List;

class Solution {
    static int[][] MOVES = {
            {1, 0}, {-1, 0}, {0, 1}, {0, -1}
    };

    static void dfs(int[][] heights, boolean[][] visited, int i, int j) {
        visited[i][j] = true;

        for (int[] move : MOVES) {
            int next_i = i + move[0];
            int next_j = j + move[1];

            if (next_i < 0 || next_i >= heights.length
                    || next_j < 0 || next_j >= heights[0].length) {
                continue;
            }

            if (visited[next_i][next_j]) {
                continue;
            }

            // 바다에서 역방향으로 올라가므로
            // 현재 높이보다 높거나 같은 곳으로만 이동
            if (heights[next_i][next_j] < heights[i][j]) {
                continue;
            }

            dfs(heights, visited, next_i, next_j);
        }
    }

    public List<List<Integer>> pacificAtlantic(int[][] heights) {
        int rows = heights.length;
        int cols = heights[0].length;

        boolean[][] po = new boolean[rows][cols];
        boolean[][] ao = new boolean[rows][cols];

        // 위 / 아래
        for (int j = 0; j < cols; j++) {
            dfs(heights, po, 0, j);
            dfs(heights, ao, rows - 1, j);
        }

        // 왼쪽 / 오른쪽
        for (int i = 0; i < rows; i++) {
            dfs(heights, po, i, 0);
            dfs(heights, ao, i, cols - 1);
        }

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

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (po[i][j] && ao[i][j]) {
                    answer.add(List.of(i, j));
                }
            }
        }

        return answer;
    }
}
  • 패턴: Depth-First Search, Backtracking
  • 설명: 제시 코드에서 물이 흐를 수 있는 경로를 DFS로 탐색해 각 위치가 두 바다에 닿는지 확인합니다. 각 방향으로 재귀적으로 탐색하며 방문 여부를 기록해 중복 방문을 방지하고 가능한 경로를 확인합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(R * C)
Space O(R * C)

피드백: 각 셀에 대해 두 번의 DFS를 수행해야 하므로 전체적으로 행/열의 면적에 비례한 시간과 공간 복잡도를 갖습니다.

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

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

@dalestudy

dalestudy Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

📊 ICE0208 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
linked-list-cycle Easy ✅ 의도한 유형
pacific-atlantic-water-flow Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

카테고리 진행도 완료
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)
Binary ■■■□□□□ 2 / 5 (Easy 2)
Linked List ■■□□□□□ 2 / 6 (Easy 2)
Heap ■■□□□□□ 1 / 3 (Medium 1)
Tree ■■□□□□□ 4 / 14 (Medium 3, Easy 1)
Graph ■■□□□□□ 2 / 8 (Medium 2)
Interval □□□□□□□ 0 / 5 ← 아직 시작 안 함

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 1,039 74 1,113 $0.000082

@ICE0208 ICE0208 moved this to In Review in 리트코드 스터디 8기 Aug 22, 2026

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

깔끔하게 잘 해결하셨네요!

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

3 participants