Skip to content

Create 111. Minimum Depth of Binary Tree.md#11

Merged
Mike0121 merged 3 commits intomainfrom
111.-Minimum-Depth-of-Binary-Tree
Nov 1, 2025
Merged

Create 111. Minimum Depth of Binary Tree.md#11
Mike0121 merged 3 commits intomainfrom
111.-Minimum-Depth-of-Binary-Tree

Conversation

@Mike0121
Copy link
Copy Markdown
Owner

@Mike0121 Mike0121 commented May 8, 2024

Copy link
Copy Markdown

@sakupan102 sakupan102 May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ不要かと思います
2ndのコメントにありましたね

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この条件がTrueになるのは与えられたTreeがNoneの場合だけですよね。
個人的にはNoneの場合の処理は再帰の外に出しちゃって、再帰の引数にはNoneが含まれないようにしてもよいかと思いました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。内部に再帰用のhelper関数を作成して、if not rootはその外側というイメージであっていますか?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そんな感じですね

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。特に引数を増やす必要がなければ、再帰用に関数を作成しない方が良いと勝手に思っていました。

Stackを利用したDFSを追記
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ついでだから枝切りしてみます?

つまり、depth >= min_depth だったらそれ以上再帰する必要ないですよね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!確かに不要ですね。
枝刈りの処理を追記しました。

stackを利用した解法に枝刈りを追記
Comment on lines 124 to 127
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このif文逆にしてもいいですね。

@Mike0121 Mike0121 changed the title 111. Minimum Depth of Binary Tree 111. Minimum Depth of Binary Tree.md Nov 1, 2025
@Mike0121 Mike0121 changed the title 111. Minimum Depth of Binary Tree.md Create 111. Minimum Depth of Binary Tree.md Nov 1, 2025
@Mike0121 Mike0121 merged commit e24e5ac into main Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants