Simple Solution using AVL Tree concept


#1

public class Solution {
boolean flag=true;
public int height(TreeNode root){
if (root==null) return 0;
int l=height(root.left);
int r=height(root.right);
if (Math.abs(l-r)>=2) flag=false;
return Math.max(l,r)+1;

}
public int isBalanced(TreeNode A) {
    if (A==null) return 1;
    int l=height(A.left);
    int r=height(A.right);
    if (Math.abs(l-r)>=2) flag=false;
    return flag==true?1:0;
}

}