一:题目描述
二:题目解答
树的题目很多都用到了递归。我们这里也是
class Solution {
public int maxDepth(TreeNode root) {
if(root==null){
return 0;
}else{
int leftLength =maxDepth(root.left);
int rightLength =maxDepth(root.right);
return java.lang.Math.max(leftLength,rightLength)+1;
}
}
}