```
public boolean isBalanced(TreeNode root) {
return helper(root, 0)>=0;
}
public int helper(TreeNode root, int cnt){
if(root==null) return cnt;
int left = helper(root.left, cnt+1), right = helper(root.right, cnt+1);
if(left==-1||right==-1||Math.abs(left-right)>1) return -1;
return Math.max(left, right);
}
```