左右子树深度较大者加 1 即为最大深度 class Solution { public: int maxDepth(TreeNode* root) { if (!root) { return 0; } return max(maxDepth(root->left), maxDepth(root->right)) + 1; } };