Skip to content

Conversation

colorbox
Copy link
Owner

return abs(right_height - left_height) <= 1 && isBalanced(root->left) && isBalanced(root->right);
}

int recursive_max_height(TreeNode* root, int current_height) {
Copy link

Choose a reason for hiding this comment

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

current_height を渡さず、 root == nullptr のときに return 0 し、 recursive_max_height() の呼び出し時の戻り値に + 1 したほが、シンプルになると思います。

Copy link

Choose a reason for hiding this comment

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

C++ では、関数名は upper camel で書くことが多いと思います。詳しくは、 Google C++ Style Guide 等をご覧ください。

Google C++ スタイルガイド(日本語全訳) Google C++ Style Guide (Japanese) https://ttsuki.github.io/styleguide/cppguide.ja.html

また、関数名は動詞で始め、関数の処理内容を必要最小限の英単語・英語句で表現することが多いと思います。今回の場合は、 GetHeight() あたりで十分だと思います。

Copy link
Owner Author

Choose a reason for hiding this comment

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

コメントありがとうございます。
leetcode側の関数命名規則に合わせていましたが、自作関数を追加する際はGoogle C++スタイルガイドに準拠します

@colorbox colorbox merged commit 49641f2 into main Nov 11, 2024
@colorbox colorbox deleted the 110 branch November 11, 2024 02:31
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.

2 participants