This is the best solution.4ms
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int max(int x, int y)
{
if(x<=y)
return y;
else
return x;
}
int maxDepth(struct TreeNode* root) {
if(root==NULL)
{
return 0;
}
else
{
return max(maxDepth(root->left),maxDepth(root->right))+1;
}
}
XIaohe-LeetCode 104 Maximum Depth of Binary Tree
原文:http://www.cnblogs.com/CathyXiaohe/p/4985401.html