import java.util.*;
/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}*/
public class Balance {
public boolean isBalance(TreeNode root) {
if(root!=null)
{
int h1 = high(root.left);
int h2 = high(root.right);
if(Math.abs(h1-h2)<=1)
{
return isBalance(root.left) & isBalance(root.right);
}
else
return false;
}
else
return true;
}
public int high(TreeNode t)
{
if(t!=null)
{
int left = high(t.left);
int right = high(t.right);
return left>right?left+1:right+1;
}
else
{
return 0;
}
}
}