[freemjstudio] WEEK 14 Solutions - #2872
Merged
Merged
Conversation
Contributor
|
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
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를 이용해 트리의 레벨 순으로 노드를 방문합니다. 큐를 사용해 각 레벨의 노드를 순회하고, 방문한 값을 모아 결과를 구성합니다. 페이지를 따라가듯 너비 우선으로 진행합니다.
Contributor
📊 freemjstudio 님의 학습 현황이번 주 제출 문제
누적 학습 요약
문제 풀이 현황
🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다. 🔢 API 사용량 (gpt-5-nano)
|
parkhojeong
approved these changes
Sep 26, 2026
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) |
Contributor
There was a problem hiding this comment.
뒤의 두 if 문을 맨 앞 조건 문 안으로 넣어주면 불필요한 if node 체크 로직을 줄일 수 있어 보이네요.
dolphinflow86
approved these changes
Sep 26, 2026
dolphinflow86
left a comment
Contributor
There was a problem hiding this comment.
이번주도 고생하셨습니다.
프로젝트 설정이 안되어있어서 이 부분 확인해주시면 감사하겠습니다.
| @@ -0,0 +1,31 @@ | |||
| from collections import deque | |||
Contributor
There was a problem hiding this comment.
복잡도 분석을 주석으로 써주시면 좋을 것 같아요
| queue.append(root) | ||
|
|
||
| while queue: | ||
| temp = [] |
Contributor
There was a problem hiding this comment.
temp 보다 조금 더 명시적으로 드러나는 변수명을 써주시면 좋을 것 같습니다~
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!