Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public class BalancedTree {
  2.     public static void main(String[] args) {
  3.         TreeNode node = null;
  4.         System.out.println(cheeckTree(node));
  5.  
  6.     }
  7.  
  8.  
  9.  
  10.     public static Boolean cheeckTree(TreeNode root) {
  11.         if (root == null) {
  12.             return false;
  13.         }
  14.  
  15.         return Math.abs(getHeight(root.left) - getHeight(root.right)) < 2;
  16.  
  17.     }
  18.  
  19.     public static int getHeight(TreeNode root) {
  20.         if (root == null) {
  21.             return 0;
  22.         }
  23.         return Math.max(getHeight(root.left), getHeight(root.right)) + 1;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement