首页 > 其他 > 详细

[leetcode] 190. Reverse Bits 解题报告

时间:2017-10-31 14:55:56      阅读:254      评论:0      收藏:0      [点我收藏+]

递归,注意结果的三重判断

public boolean isBalanced(TreeNode root) {
        if (root==null) return true;
        return Math.abs(getHeight(root.left)-getHeight(root.right)) <=1 && isBalanced(root.left) && isBalanced(root.right);
    }

    public int getHeight(TreeNode node){
        if (node==null){
            return 0;
        }
        if (node.right == null && node.left ==null){
            return 1;
        }
        return Math.max(getHeight(node.left),getHeight(node.right))+1;
    }

 

[leetcode] 190. Reverse Bits 解题报告

原文:http://www.cnblogs.com/pulusite/p/7761471.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!