题解 | #判断是不是平衡二叉树#
判断是不是平衡二叉树
http://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222
public class Solution {
boolean isBa = true;
public boolean IsBalanced_Solution(TreeNode root) {
isBa = true;
height(root);
return isBa;
}
public int height(TreeNode root) {
if(root == null) {
return 0;
}
int le = height(root.left);
int ri = height(root.right);
if(Math.abs(le - ri) > 1) {
isBa = false;
}
return Math.max(le, ri) + 1;
}
}