直接递归求解即可:
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root==NULL)
return 0;
else
return 1+max(maxDepth(root->left),maxDepth(root->right));
}
};
直接递归求解即可:
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root==NULL)
return 0;
else
return 1+max(maxDepth(root->left),maxDepth(root->right));
}
};