Skip to content

[yuseok89] WEEK 10 Solutions - #2836

Open
yuseok89 wants to merge 1 commit into
DaleStudy:mainfrom
yuseok89:main
Open

[yuseok89] WEEK 10 Solutions#2836
yuseok89 wants to merge 1 commit into
DaleStudy:mainfrom
yuseok89:main

Conversation

@yuseok89

@yuseok89 yuseok89 commented Aug 24, 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.

🏷️ 알고리즘 패턴 분석

invert-binary-tree/yuseok89.py
# TC: O(N)
# SC: 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 invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:

        if not root:
            return None
        else:
            cur_node = TreeNode(root.val)

            cur_node.right = self.invertTree(root.left)
            cur_node.left = self.invertTree(root.right)

            return cur_node
  • 패턴: Binary Search, Depth-First Search, Divide and Conquer
  • 설명: 이 코드는 이진트리의 자식 노드를 서로 바꿔 트리를 반전시키는 재귀적 분할 처리로서, DFS 방식으로 각 서브트리를 처리하며 분할해서 해결하는 패턴을 사용합니다.

📊 시간/공간 복잡도 분석

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

피드백: 트리의 각 노드를 한 번씩 방문하여 자식 정보를 교환하므로 시간 복잡도는 O(n)이고, 재귀 호출 스택의 깊이에 비례하는 공간 복잡도 O(h)이다.

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

@github-actions github-actions Bot added the py label Aug 24, 2026
@dalestudy

dalestudy Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

📊 yuseok89 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
invert-binary-tree Easy ⚠️ 유형 불일치

누적 학습 요약

  • 풀이한 문제: 44 / 75개
  • 이번 주 유형 일치율: 0% (1문제 중 0문제 일치)

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 347 37 384 $0.000032

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.

앞의 if가 이미 리턴을 하고 있어서 else 를 크게 쓰지 않으셔도 되지 않을까? 라는 생각이 듭니다!
또한 cur_node 를 만들지 않으시고 root를 직접 바꾸셔도 정답처리 되실거에요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Solving

Development

Successfully merging this pull request may close these issues.

2 participants