首页 > 其他 > 详细

LF.60.Height Of Binary Tree

时间:2018-03-27 14:15:55      阅读:208      评论:0      收藏:0      [点我收藏+]

 

Find the height of binary tree.

Examples:

        5

      /    
    3        8

  /   \        
1      4        11

The height of above binary tree is 3.

 

 1 public class Solution {
 2   public int findHeight(TreeNode root) {
 3     // Write your solution here
 4     if (root == null) {
 5         return 0;
 6     }
 7     int leftRes = findHeight(root.left);
 8     int rightRes = findHeight(root.right) ;
 9     return Math.max(leftRes, rightRes) + 1 ;
10   }
11 }

 

LF.60.Height Of Binary Tree

原文:https://www.cnblogs.com/davidnyc/p/8656480.html

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