题目描述
平衡二叉树左右子树高度差不超过 1。
public class Solution {
// 求深度
public int TreeDepth(TreeNode root) {
return root == null ? 0 : Math.max(TreeDepth(root.left)+1, TreeDepth(root.right)+1);
}
public boolean IsBalanced_Solution(TreeNode root) {
if(root == null)
return true;
int left = TreeDepth(root.left);
int right = TreeDepth(root.right);
return Math.abs(left - right) > 1 ? false : true && IsBalanced_Solution(root.left) && IsBalanced_Solution(root.right);
}
}