标签:
题目描述输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。
代码:
<span style="color:#993399;">public class Solution {
public int TreeDepth(TreeNode pRoot){
if(pRoot==null)
return 0;
return getDepth(pRoot,0);
}
private int getDepth(TreeNode root,int depth){
if(root==null)
return depth;
depth++;
return Math.max(getDepth(root.left,depth),getDepth(root.right,depth));
}
}</span>标签:
原文地址:http://blog.csdn.net/baidu_21578557/article/details/51620357