Balanced Binary Tree
1 public class Solution { 2 public boolean isBalanced(TreeNode root) { 3 if(root==null) return true; 4 if(checkHeight(root)==-1) return false; 5 return true; 6 } 7 public int checkHeight(TreeNode root){ 8 if(root==null) return 0; 9 int left = checkHeight(root.left); 10 int right = checkHeight(root.right); 11 if(right==-1||left==-1) return -1; 12 if(Math.abs(left-right)>1) return -1; 13 return Math.max(left,right)+1; 14 } 15 }