public class Solution {
public boolean IsBalanced_Solution(TreeNode root) {
int ret = isbalanced(root) ;
if (ret < 0) {
return false;
}
return true;
}
public int isbalanced(TreeNode root) {
if (root == null) return 0;
int lH = isbalanced(root.left);
int rH = isbalanced(root.right);
int h = Math.max(lH, rH) + 1;
if (lH < 0 || rH < 0) {
return -1;
}
if (Math.abs(lH - rH) > 1) {
return -1;
}
return h;
}
}



京公网安备 11010502036488号