题意:
求出树的最大深度。
思路:
DFS。
代码如下:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root) {
int r,l;
if(root==NULL){
return 0;
}
l=maxDepth(root->left)+1;
r=maxDepth(root->right)+1;
return l>r?l:r;
}