Create 111. Minimum Depth of Binary Tree.md#11
Merged
Conversation
sakupan102
reviewed
May 9, 2024
sakupan102
reviewed
May 9, 2024
There was a problem hiding this comment.
この条件がTrueになるのは与えられたTreeがNoneの場合だけですよね。
個人的にはNoneの場合の処理は再帰の外に出しちゃって、再帰の引数にはNoneが含まれないようにしてもよいかと思いました。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。内部に再帰用のhelper関数を作成して、if not rootはその外側というイメージであっていますか?
Owner
Author
There was a problem hiding this comment.
ありがとうございます。特に引数を増やす必要がなければ、再帰用に関数を作成しない方が良いと勝手に思っていました。
Stackを利用したDFSを追記
oda
reviewed
May 11, 2024
There was a problem hiding this comment.
ついでだから枝切りしてみます?
つまり、depth >= min_depth だったらそれ以上再帰する必要ないですよね。
Owner
Author
There was a problem hiding this comment.
ありがとうございます!確かに不要ですね。
枝刈りの処理を追記しました。
stackを利用した解法に枝刈りを追記
TORUS0818
reviewed
Jul 15, 2024
Comment on lines
124
to
127
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/