标签:
题目:求二叉树的深度
思路:递归求二叉树的深度
实现代码:
/* 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; } }
标签:
原文地址:http://www.cnblogs.com/wxisme/p/5460311.html