public class Solution {
public boolean IsBalanced_Solution(TreeNode root) {
if (root == null) {
return true;
}
int leftHeight = treeDeepHeight(root.left);
int rightHeight = treeDeepHeight(root.right);
int heightMinus = Math.abs(leftHeight - rightHeight);
if (heightMinus > 1) {
return false;
}
return IsBalanced_Solution(root.left) && IsBalanced_Solution(root.right);
}
public int treeDeepHeight (TreeNode root) {
if (root == null) {
return 0;
}
return Math.max(treeDeepHeight(root.left), treeDeepHeight(root.right)) + 1;
}
}