/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** * * @param root TreeNode类 * @return int整型 */ int maxDepth(TreeNode* root) { // write code here if(root == nullptr) // 递归返回临界 return 0; else if(!root->left && !root->right) // 递归返回临界 return 1; return max(maxDepth(root->left), maxDepth(root->right)) + 1; } };