题解 | #判断是不是平衡二叉树#

判断是不是平衡二叉树

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;
    }
}
全部评论

相关推荐

03-10 11:23
门头沟学院 Java
鹿LF:计算机面试就跟数学题一样,没什么实际价值,但只能这么筛选,本质是考察你的努力,智力和学习能力
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
03-30 21:35
爱蜜莉雅碳劝退测开:裁员裁大动脉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务