6ms clean c solution


  • 0
    T
    // (min, max)
    bool isValidBSTHelper(struct TreeNode* root, long long int min, long long int max) {
        if(root) {
            if(min<root->val&&max>root->val)
                return isValidBSTHelper(root->left, min, root->val) && isValidBSTHelper(root->right, root->val, max);
            else
                return false;
        } else
            return true;
    }
    bool isValidBST(struct TreeNode* root) {
        return isValidBSTHelper(root, -100000000000, 100000000000);
    }
    

Log in to reply
 

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