首页 > 其他 > 详细

110. Balanced Binary Tree

时间:2019-04-07 16:28:14      阅读:108      评论:0      收藏:0      [点我收藏+]

 

class Solution {
public:
    bool isBalanced(TreeNode* root) {
        int depth = 0;
        return Balanced(root,depth);
    }
    bool Balanced(TreeNode* root,int& depth){
        if(root == NULL){
            depth = 0;
            return true;
        }
        int left,right;
        if(Balanced(root->left,left) && Balanced(root->right,right)){
            int gap = left - right;
            if(gap <= 1 && gap >= -1){
                depth = left > right ? left + 1 : right + 1;
                return true;
            }
        }
        return false;
    }
};

 

110. Balanced Binary Tree

原文:https://www.cnblogs.com/ymjyqsx/p/10665686.html

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