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; }
本站公眾號
   歡迎關注本站公眾號,獲取更多信息