Open
Conversation
oda
reviewed
Dec 9, 2025
| - ドキュメントを確認したが、よく理解できなかった。 | ||
| - q.front()自体は参照だけど、一度[e]というローカル変数へコピーされる | ||
| - nodeとdepthはそのコピーeのメンバへの参照 | ||
| - queueの中身には結びついていない。こんな理解でいいのかな |
t9a-dev
reviewed
Dec 9, 2025
| return 0; | ||
| } | ||
|
|
||
| std::queue<std::pair<TreeNode*, int>> q; |
There was a problem hiding this comment.
変数名qについて、自分はfrontiersにするかなと思いました。これから見る予定のものを詰め込んでいくという感覚で使っています。
LeetCodeの回答のような短い処理では変数名qでも問題ないと思いますが、コーディング練習の観点から語彙の提案という目的でコメントしました。
naoto-iwase
reviewed
Dec 9, 2025
|
|
||
| ### 解法を考える。 | ||
| - maximumと同じようにDFS実行すると、勿体無いのでBFSで最小深さがいいのか | ||
| - DFSでもmin(minDepth(root->left), minDepth(root->right))で求められるのか |
There was a problem hiding this comment.
DFSでも、根からの深さを持ちながら全探索を行い、葉に到達するたびにmin_depth = min(min_depth, depth)と更新することで最小深さを求められますね。
| return 0; | ||
| } | ||
|
|
||
| std::vector<TreeNode*> current_nodes; |
There was a problem hiding this comment.
current_nodesだと個人的に情報量が少ないと感じるので、自分ならnodes_in_depthやfrontiersなどと名付けます。
|
全体的に読みやすかったです。 |
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.
This: https://leetcode.com/problems/minimum-depth-of-binary-tree/
Nexr: https://leetcode.com/problems/merge-two-binary-trees/