ctci4.1

int highAve(struct tree* root){
    if(root == NULL)
        return 0 ;
    int lefthigh = highAve(root->left);
    int righthigh = highAve(root->right);
    if(abs(lefthigh - righthigh) >=2 )
        return -1;
    else
        return max(lefthigh,righthigh);
}

bool isAve(struct tree* root){
    if(highAve(root) == -1)
        return false;
    else
        return true;
}
posted @ 2014-10-09 16:34  lycan785  阅读(172)  评论(0编辑  收藏  举报