解题代码:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root){
if(root==NULL)
{
return 0;
}
int nleft=maxDepth(root->left);
int nright=maxDepth(root->right);
return 1+fmax(nleft,nright);
}