Skip to content

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.

4 participants