Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

111. Minimum Depth of Binary Tree #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

111. Minimum Depth of Binary Tree #36

wants to merge 1 commit into from

Conversation

if (!node) {
continue;
}
if (!(node->left || node->right)) {
Copy link

Choose a reason for hiding this comment

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

私は、

!node->left && !node->right

のほうが好きですが、趣味の範囲でしょうか。

この問題がこれくらいで書けていたら特に問題ないと思います。

nodes_and_depths.emplace(node->left, depth + 1);
nodes_and_depths.emplace(node->right, depth + 1);
}
return 0;
Copy link

Choose a reason for hiding this comment

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

ここがでてくるのは、root == nullptr のときだけでしょうか。一番上にするのも一つかなと思います。

@hroc135
Copy link

hroc135 commented Jan 20, 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.

3 participants