LF.60.Height Of Binary Tree

 

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 }

 

posted @ 2018-03-27 11:23  davidnyc  阅读(77)  评论(0编辑  收藏  举报