public class Solution {

```
public boolean isBalanced(TreeNode root) {
if (root == null) return true;
boolean isB = true;
int left_h = dep(root.left);
int right_h = dep(root.right);
if ( Math.abs(left_h - right_h) > 1||
isBalanced(root.left) == false||
isBalanced(root.right) == false )
isB = false;
return isB;
}
private int dep(TreeNode root){
if (root == null) return 0;
return 1 + Math.max(dep(root.left), dep(root.right));
}
```

}