Skip to content

[freemjstudio] WEEK 14 Solutions - #2872

Merged
parkhojeong merged 1 commit into
DaleStudy:mainfrom
freemjstudio:freemjstudio-week14
Sep 27, 2026
Merged

parkhojeong merged 1 commit into
DaleStudy:mainfrom
freemjstudio:freemjstudio-week14

Conversation

@freemjstudio

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Sep 26, 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.

🏷️ 알고리즘 패턴 분석

binary-tree-level-order-traversal/freemjstudio.py
from collections import deque

# 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 levelOrder(self, root: TreeNode | None) -> list[list[int]]:
        visits = []

        # bfs
        queue = deque([])
        queue.append(root)

        while queue:
            temp = []
            for _ in range(len(queue)):
                node = queue.popleft()
                if node:
                    temp.append(node.val)

                if node and node.left:
                    queue.append(node.left)
                if node and node.right:
                    queue.append(node.right)
            if temp:
                visits.append(temp)

        return visits
  • 패턴: BFS, Binary Search
  • 설명: 코드가 BFS를 이용해 트리의 레벨 순으로 노드를 방문합니다. 큐를 사용해 각 레벨의 노드를 순회하고, 방문한 값을 모아 결과를 구성합니다. 페이지를 따라가듯 너비 우선으로 진행합니다.

@dalestudy

dalestudy Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

📊 freemjstudio 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
binary-tree-level-order-traversal Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

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

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

이번 주도 수고하셨습니다!

Comment on lines +21 to +27
if node:
temp.append(node.val)

if node and node.left:
queue.append(node.left)
if node and node.right:
queue.append(node.right)

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 문을 맨 앞 조건 문 안으로 넣어주면 불필요한 if node 체크 로직을 줄일 수 있어 보이네요.

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

이번주도 고생하셨습니다.
프로젝트 설정이 안되어있어서 이 부분 확인해주시면 감사하겠습니다.

@@ -0,0 +1,31 @@
from collections import deque

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.

복잡도 분석을 주석으로 써주시면 좋을 것 같아요

queue.append(root)

while queue:
temp = []

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.

temp 보다 조금 더 명시적으로 드러나는 변수명을 써주시면 좋을 것 같습니다~

@parkhojeong
parkhojeong merged commit e8d5488 into DaleStudy:main Sep 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants