思路:树的深度 = 左右子树最大的深度 + 1
code:
class Solution {
public:
int maxDepth(TreeNode *root) {
if(root)
return max(maxDepth(root->left), maxDepth(root->right)) + 1;
return 0;
}
};
思路:树的深度 = 左右子树最大的深度 + 1
code:
class Solution {
public:
int maxDepth(TreeNode *root) {
if(root)
return max(maxDepth(root->left), maxDepth(root->right)) + 1;
return 0;
}
};