```
class Solution {
boolean result = true;
public boolean isBalanced(TreeNode root)
{
diff(root);
return result;
}
public int diff(TreeNode node)
{
if (node == null) return 0;
int left = diff(node.left);
int right = diff(node.right);
if (Math.abs(left - right) > 1) result = false;
return Math.max(left, right) + 1;
}
}
```