my java traversal solution


  • 0
    C
    public class Solution {
    
    int last_lower_bound = Integer.MIN_VALUE;
    boolean firstnode = true;
    
    public boolean isValidBST(TreeNode root) {
        if(root == null)
            return true;
        
        if(isValidBST(root.left) == false)
            return false;
        
        if(!firstnode && last_lower_bound>=root.val)
            return false;
            
        firstnode=false;
        last_lower_bound = root.val;
        
        if(isValidBST(root.right) == false)
            return false;
        
        return true;
    }
    

    }


Log in to reply
 

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