class Tree
{
boolean isBalanced(Node root)
{
int lht = heightleft(root.left);
int rht = heightright(root.right);
int ht=Math.abs(lht-rht);
if(ht>1)
return false;
else
return true;
}
int heightleft(Node root)
{
if(root==null)
return 0;
return(Math.max(heightleft(root.left),heightleft(root.right)))+1;
}
int heightright(Node root)
{
if(root==null)
return 0;
int rr1=heightright(root.right);
int rr2=heightright(root.left);
return (Math.max(rr1,rr2))+1;
}
}