当前位置:首页 > 开发教程 > 软件工程 >

剑指offer(四十五)之二叉树的深度

时间:2016-06-09 20:23 来源: 作者: 收藏

工具介绍:1. XdebugXdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),相当强大,它可以用来跟踪,调试和分析PHP程序的运行状况。Xdebug现在的最新版本是Xdebug 2.1.0, 下载页面是 http://xdebug.org/download.php,注意页面中下载链接有多个(如下图 题目描述

输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。

代码:

<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>


0
0
   

软件工程阅读排行

最新文章