Skip to content

[parkhojeong] WEEK 12 Solutions - #2858

Merged
parkhojeong merged 3 commits into
DaleStudy:mainfrom
parkhojeong:week12
Sep 13, 2026
Merged

[parkhojeong] WEEK 12 Solutions#2858
parkhojeong merged 3 commits into
DaleStudy:mainfrom
parkhojeong:week12

Conversation

@parkhojeong

@parkhojeong parkhojeong commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

⚠️ Week 설정이 누락되었습니다

프로젝트에서 Week를 설정해주세요!

설정 방법

  1. PR 우측의 Projects 섹션에서 리트코드 스터디 옆 드롭다운(▼) 클릭
  2. 현재 주차를 선택해주세요 (예: Week 14(current) 또는 Week 14)

📚 자세한 가이드 보기


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

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.

🏷️ 알고리즘 패턴 분석

number-of-connected-components-in-an-undirected-graph/parkhojeong.py
class Solution:
    def countComponents(self, n: int, edges: List[List[int]]) -> int:
        edge_dic = {i: [i] for i in range(n)}

        for edge in edges:
            start, end = sorted(edge)
            edge_dic[start].append(end)
            edge_dic[end].append(start)

        def traverse(idx: int):
            while edge_dic[idx]:
                end = edge_dic[idx].pop()
                traverse(end)

        cnt = 0
        for i in range(n):
            if len(edge_dic[i]) > 0:
                cnt += 1
                traverse(i)

        return cnt
  • 패턴: Depth-First Search, Hash Map / Hash Set
  • 설명: 그래프를 DFS로 탐색하며 연결 성분의 개수를 센다. 각 정점의 인접 리스트를 해시 맵으로 관리하고, 방문 여부를 리스트 길이로 판단한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n + m)
Space O(n + m)

피드백: 인접 리스트를 한 방향으로만 탐색하는 재귀가 없이 스택으로 구현되어 있고, 각 정점을 한 번씩 방문하므로 시간은 간선 수와 정점 수의 합에 비례한다.

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

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

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/parkhojeong.py
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
        cnt = 0
        cur = head
        while cur:
            cnt += 1
            cur = cur.next

        dummy = ListNode()
        dummy.next = head
        prev = dummy
        cur = head
        i = 0
        while cur:
            if cnt - n == i:
                prev.next = cur.next
                break

            prev = cur
            cur = cur.next
            i += 1

        return dummy.next
  • 패턴: Two Pointers, Linked List
  • 설명: 두 포인터를 이용해 끝에서 n번째 노드를 제거하는 과정을 구현하므로 Two Pointers 패턴이 가장 적합합니다. 또한 Linked List 구조를 다루는 일반적인 패턴으로 linked list 관련 흐름도 같이 보입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(L)
Space O(1)

피드백: 카운트를 이용해 두 번째 포인터를 조정하는 방식으로 추가 포인터를 사용하지 않고도 제거 가능하다.

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

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

Comment thread same-tree/parkhojeong.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/parkhojeong.py
# 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:
        if p is None and q is None:
            return True

        if (p is None and q is not None) or (p is not None and q is None):
            return False

        if (p.left or q.left) and not self.isSameTree(p.left, q.left):
            return False

        if (p.right or q.right) and not self.isSameTree(p.right, q.right):
            return False

        return p.val == q.val
  • 패턴: Depth-First Search, Binary Search, Hash Map / Hash Set
  • 설명: 트리 구조를 재귀적으로 순회하며 두 트리의 노드 값을 비교하고 좌우 자식까지 동일 여부를 확인하는 방식으로 동작합니다. 재귀를 통해 DFS 형태로 같은지 여부를 깊이 우선으로 검사합니다.

📊 시간/공간 복잡도 분석

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

피드백: 각 재귀 호출이 트리의 같은 위치의 노드를 비교하며, 최악의 경우 트리 높이에 비례하는 공간이 필요하다.

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

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

@dalestudy

dalestudy Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

📊 parkhojeong 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
number-of-connected-components-in-an-undirected-graph Medium ✅ 의도한 유형
remove-nth-node-from-end-of-list Medium ✅ 의도한 유형
same-tree Easy ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 1,121 118 1,239 $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.

이거 Single pass로 해결하는게 진짜 괜찮던데 한번 시도 해 보시는것도 좋겠네요

@parkhojeong parkhojeong Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

네 한 번 시도해보겠습니다!

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

고생하셨습니다.

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

초반에 엄청나게 많은 조건들 정리하는게 가독성 상 좋지 않을까요?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

정리하는게 좋겠네요. 감사합니다!

@parkhojeong
parkhojeong merged commit 6f20d09 into DaleStudy:main Sep 13, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from Solving to Completed in 리트코드 스터디 8기 Sep 13, 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