68 cases passed... can someone suggest me how to handle the corner cases?? I am confused.


  • 0
    H
    /**
     * Definition for binary tree
     * struct TreeNode {
     *     int val;
     *     TreeNode *left;
     *     TreeNode *right;
     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     * };
     */
    class Solution {
    public:
        int prev = INT_MIN;
        bool isValidBST(TreeNode *root) {
            if(root == NULL)
                return true;
    
            if(isValidBST(root->left) && (prev < root->val)){
                prev = root->val;
                return (isValidBST(root->right));
            }
            
            return false;
            
        }
    };
    

    This is my solution.. I am not able to handle the case with INT_MIN element in it. I tried LLONG_INT but it seems it is not working too.


  • 0
    H

    Used long long prev = LLONG_MIN, then it works fine....but any other way??


Log in to reply
 

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