题目链接:https://leetcode.com/problems/maximum-depth-of-binary-tree/
求树的最大深度,一言以蔽之:子节点树的最大深度加1就是父节点树的最大深度。递归题目想通了就好简单!!!
class Solution {
public int maxDepth(TreeNode root) {
int m=0;
int n=0;
if(root==null )
return 0;
else
{
m=maxDepth(root.left)+1;
n=maxDepth(root.right)+1;
}
return m>n?m:n;
}
}