```
public class Solution {
boolean ret;
public boolean isBalanced(TreeNode root) {
ret = true;
helper(root);
return ret;
}
public int helper(TreeNode root){
if(root == null) return 1;
int temp1 = helper(root.left);
int temp2 = helper(root.right);
if(Math.abs(temp1-temp2) > 1) ret = false;
return Math.max(temp1+1, temp2+1);
}
}
```