题目描述
求给定二叉树的最大深度,
最大深度是指树的根结点到最远叶子结点的最长路径上结点的数量。
int ldep = 0,rdep = 0;
public int maxDepth (TreeNode root) {
if(root==null){
return 0;
}else if(root.left==null && root.right==null){
return 1;
}else{
return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
}
}