Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. // returns -1 if it is not bst, otherwise it is bst
  2. int ifBST(BSTnode * root){
  3.     odp o;
  4.     o.ok=true;
  5.     if(root == NULL){
  6.         return 0;
  7.     }
  8.     else{
  9.         int leftHeight = ifBST(root->left) , rightHeight = ifBST(root->right);
  10.         if(leftHeight == -1 || rightHeight == -1 || abs(rightHeight - leftHeight)>1){
  11.             return -1;
  12.         }
  13.         return  1 + max(leftHeight, rightHeight);
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement