思路:后序遍历判断左右子树高度是否满足平衡二叉树
public class Solution {
boolean flag = true;
public int deep(TreeNode root){
if(root == null){
return 0;
}
int left = deep(root.left);
int right = deep(root.right);
if(Math.abs(left-right)>1){
flag = false;
}
return left>right?left+1:right+1;
}
public boolean IsBalanced_Solution(TreeNode root) {
deep(root);
return flag;
}
}