class Solution {
public boolean isBalanced(TreeNode root) {
if(root==null){
return true;
}
int leftDepth = depth(root.left);
int rightDepth = depth(root.right);
return Math.abs(leftDepth-rightDepth)>1 ? false:isBalanced(root.left) && isBalanced(root.right);
}
public int depth(TreeNode root){
if(root == null)
return 0;
return Math.max(depth(root.left),depth(root.right))+1;
}
}



