Open
Conversation
mamo3gr
reviewed
Jan 13, 2026
| while frontiers: | ||
| next_frontiers = [] | ||
| for node in frontiers: | ||
| if node.left is None and node.right is None: |
There was a problem hiding this comment.
過去にいただいたレビューコメントの受け売りなのですが、つまり何を判定しているのかをbooleanやinner functionの名前で表すと分かりやすいです。
Suggested change
| if node.left is None and node.right is None: | |
| is_leaf = node.left is None and node.right is None | |
| if is_leaf: |
mamo3gr
reviewed
Jan 13, 2026
| if root is None: | ||
| return 0 | ||
|
|
||
| node = root |
There was a problem hiding this comment.
node に置き直す意図が見えませんでした。
- 置かない。
rootのまま書いちゃう nodeを取るヘルパー関数を書いて、return helper(root)する- どうしても置くなら、
Noneチェックの前にする
のいずれかが良さそうに思いました(自分ならこうするかなーという優先順)。
05ryt31
reviewed
Jan 13, 2026
| if root is None: | ||
| return 0 | ||
|
|
||
| node = root |
There was a problem hiding this comment.
自分も下でmamoさんがおっしゃっているように、rootをnodeで置き換えずにそのまま使って書いたものが一番シンプルでわかりやすいかなと思いました。
個人的には下のコードよりもこちらの方が好きです。
| ## Step3 | ||
| 再帰で練習 | ||
| ```py | ||
| class Solution: |
There was a problem hiding this comment.
全くもって自明ではある(し、自分もやっていないので人のこと言えない)んですが、TreeNodeクラスを定義しておくと、可読性は上がりそうですね。
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.
解く問題
Minimum Depth of Binary Tree
次に解く問題
Merge Two Binary Trees