Why Always Wrong …… [Validate Binary Search Tree]


  • 0
    I
    bool ret;
    int pre = -1000000000;
    void dfs(TreeNode *root)
    {
        if (root == NULL) return ;
        dfs(root->left);
        if (root->val < pre) ret = false;
        pre = root->val;
        dfs(root->right);
    }
    class Solution {
    public:
        bool isValidBST(TreeNode *root) {
            ret = true;
            dfs(root);
            return ret;
        }
    };
    
    
    
    
    /****************************/
    Input: 	{0,-1}
    Output: 	false
    Expected: 	true
    /**************************/
    

    Who can tell me why , i think it's right...


Log in to reply
 

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