Failed case [2147483647], please help


  • 0
    X
    class Solution {
    public:
        bool isValidBST(TreeNode* root) {
            return isBST(root,INT_MIN,INT_MAX);
        }
    private:
        bool isBST(TreeNode* root, int min, int max)
        {
            if (root==NULL)
            return true;
            else if ((root->val<max && root->val>min) && isBST(root->left, min, root->val) && isBST(root->right, root->val, max))
            return true;
            else 
            return false;
            
        }
    };
    

    This C++ code failed at case [2147483647] which expected to be true. please enlighten me!


  • 1
    Y

    Note that INT_MAX = 2147483647.


  • 0
    Y

    right, i used to have the same problem. I fixed with changing the default boundaries to null object


Log in to reply
 

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