二叉树的深度

题目:求二叉树的深度

思路:递归求二叉树的深度

实现代码:

/*
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
        this.val = val;
    }
};*/
public class Solution {
    public int TreeDepth(TreeNode pRoot) {
        if(pRoot == null)
            return 0;
        
        int leftDepth = TreeDepth(pRoot.left);
        int rightDepth = TreeDepth(pRoot.right);
        
        return leftDepth>rightDepth?leftDepth+1:rightDepth+1;
    }
}

 

posted @ 2016-05-05 00:07  Pickle  阅读(249)  评论(0编辑  收藏  举报