import java.util.*;
public class Balance {
public boolean isBalance(TreeNode root) {
if(root==null){
return true;
}
if(Math.abs(depth(root.left)-depth(root.right))>1){
return false;
}
else{
return isBalance(root.left)&isBalance(root.right);
}
}
public int depth(TreeNode root){
if(root==null){
return 0;
}else{
return Math.max(depth(root.left),depth(root.right))+1;
}
}
}