首页 > 其他 > 详细

38二叉树的深度

时间:2018-01-02 11:09:15      阅读:209      评论:0      收藏:0      [点我收藏+]

题目描述

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

public class Solution {
public int TreeDepth(TreeNode root) {
return depth(root);
}
private int depth(TreeNode root){
if(root==null) return 0;
int left = depth(root.left);
int right = depth(root.right);
if(left>right) return left+1;
else return right+1;

}
}

38二叉树的深度

原文:https://www.cnblogs.com/zle1992/p/8175797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!