How to fix my code , last input [-2147483648]?


  • 0
    G
    public class Solution {  
    public int previous = Integer.MIN_VALUE;  
    public boolean isValidBST(TreeNode root) {  
        if(root == null)  
            return true;  
            
        //the left sub tree  
        if(!isValidBST(root.left))  
            return false;  
            
        //the current node  
        if(root.val <= previous)  
            return false;  
        previous = root.val;  
      
        //the right subtree  
        return isValidBST(root.right);
    }  
    

    }


  • 0

    Well you made previous static, meaning the same variable will be used for all test cases, without resetting it in between. That's no good.


  • 0
    G

    oh,thank you!


Log in to reply
 

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