Open
Conversation
oda
reviewed
Jan 7, 2025
| 自分でもその方式で実装する。 | ||
| 階層ごとに処理する今回の方法の場合、各階層でやりたい処理が追加である場合に対応しやすいが | ||
| タプルで管理する方法は階層の深さを明示しなくても常に今の深さが分かる点がある。 | ||
| 今回だと深さを知りたいだけなので、趣味の範囲かなと思った。 |
There was a problem hiding this comment.
趣味の範囲なんですが、個人的な意見として、queue の中身のデータの整合性が取れているということは、読んでいる人からすると全部読み終わらないと分からないからです。書いている人は分かるわけですが。
つまり、一つの変数に、2つの違う種類のものを入れておいて、その境界を個数で管理しているわけですよね。
リスト2つ使って this_level, next_level を入れ替えていくという方法もあります。
Owner
Author
There was a problem hiding this comment.
たしかに読み手からすると全部読み終わらないと分からないですね。
リスト2つ使って this_level, next_level を入れ替えていくという方法もあります。
こちらもstep4で書いてみます。
hroc135
reviewed
Jan 11, 2025
| ``` | ||
|
|
||
| スタックを用いた再帰 | ||
| これだと全部の葉を調べる必要があるので、これをするなら最初の BFS を用いたコードを書くなあ。 |
There was a problem hiding this comment.
スタックを用いたDFSですね
スタックDFSも再帰DFSもどちらも全ノードを探索することになると思います
hroc135
reviewed
Jan 11, 2025
| return 0 | ||
|
|
||
| depth = 1 | ||
| queue = deque([root]) |
There was a problem hiding this comment.
すでに指摘されていますが、自分もここはqueueを使う必要がない点が気になりました
nittoco
reviewed
Jan 13, 2025
Comment on lines
+34
to
+35
| if root.left is None and root.right is None: | ||
| return 1 |
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/minimum-depth-of-binary-tree/description/