Skip to content

111. Minimum Depth of Binary Tree #36

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

Merged
merged 1 commit into from
Mar 9, 2025
Merged

111. Minimum Depth of Binary Tree #36

merged 1 commit into from
Mar 9, 2025

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

いいと思います。あとは深さごとのノードをひとまとめの配列にして更新していく方法があると思います

@colorbox colorbox merged commit aeac2ee into main Mar 9, 2025
@colorbox colorbox deleted the 111 branch March 9, 2025 14:34
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