Very simple recursive solution.


  • 0
    R
    bool isbst(struct TreeNode* root,long minval,long maxval){
    if(!root)return true;
    return (root->val<maxval)&&(root->val>minval)&&isbst(root->left,minval,root->val)&&isbst(root->right,root->val,maxval);	
    }
    
    bool isValidBST(struct TreeNode* root) {
        return isbst(root,LONG_MIN,LONG_MAX);
    }

  • 0
    A

    This is not working for me now. It worked for me lasy year but now test cases are throwing up wrong answers.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.