描述:
分析:
只需要看左右子树的深度差小于等于1,且左右子树都是平衡二叉树。
代码:
public class Solution {
public boolean IsBalanced_Solution (TreeNode pRoot) {
if (pRoot == null) return true;
return Math.abs(deep(pRoot.left) - deep(pRoot.right)) <= 1 &&
IsBalanced_Solution(pRoot.left) && IsBalanced_Solution(pRoot.right);
}
public int deep(TreeNode root) {
if (root == null )return 0;
return Math.max(deep(root.left), deep(root.right)) + 1;
}
}