二叉树的深度

输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。
思路:使用递归的方法分别计算左右子树的深度
public class Solution {
    public int TreeDepth(TreeNode pRoot){
        return pRoot == null? 0 : Math.max(TreeDepth(pRoot.left),TreeDepth(pRoot.right)) + 1;    
    }
}
原文地址:https://www.cnblogs.com/LoganChen/p/6486625.html