Untitled

mail@pastecode.io avatarunknown
plain_text
2 months ago
417 B
1
Indexable
Never
bool isbst(BinaryTreeNode<int>* root,int min,int max){
    if (root==NULL) return true;
    if(root->data >min && root->data <max){ //if in tree
        bool l=isbst(root->left,min,root->data);
        bool r=isbst(root->right,root->data,max);
        return( l&&r);
    }else{
        return false;
    }
}


bool validateBST(BinaryTreeNode<int>* root) {
    return isbst(root,INT_MIN,INT_MAX);
}