Conversation
mamo3gr
reviewed
Feb 17, 2026
| - その際に左から右に返す | ||
| - 幅優先探索で解けば良さそう | ||
| - 特に苦労なく書けた | ||
| - 方針として毎回level毎に新しくfrontierを作るか、levelもfrontierに入れて管理するか迷ったが毎回level毎に作った方がわかりやすそうだと思ったので現在の実装にした |
There was a problem hiding this comment.
step1の段階なのに視野が広く取れているなーと感心しました(自分は基本的にこの段階では解くので精一杯なので)。
mamo3gr
reviewed
Feb 17, 2026
Comment on lines
+16
to
+18
| level_order_values = [] | ||
| if root is None: | ||
| return level_order_values |
There was a problem hiding this comment.
些末ですが…
「level_order_values を空のリストとして初期化します。root が None なら level_order_values を返します。さて戻り値はなんでしょう。」というマイクロ謎解きが発生するので、ダイレクトに空のリストを返すほうが好みです。root is None なら、そもそも level_order_values という変数の存在自体を知る必要がありません。
Suggested change
| level_order_values = [] | |
| if root is None: | |
| return level_order_values | |
| if root is None: | |
| return [] | |
| level_order_values = [] |
mamo3gr
reviewed
Feb 17, 2026
| while current_level: | ||
| current_values = [] | ||
| next_level = [] | ||
| for current in current_level: |
There was a problem hiding this comment.
ここは現在の (current) というより、ノードであるという情報のほうが重要に思いました。
Suggested change
| for current in current_level: | |
| for node in current_level: |
mamo3gr
reviewed
Feb 17, 2026
|
|
||
| current_level = [root] | ||
| while current_level: | ||
| current_values = [] |
There was a problem hiding this comment.
細かいですが、current_ と対応する next_values は登場せず、ライフタイムもこのループ内だけなので values でも良さそうに感じました。current_level と関係があることを示唆する current_level_values でもいいかもしれません。
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.
この問題:https://leetcode.com/problems/binary-tree-level-order-traversal/
次の問題:https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/