A JAVA code to be improved


  • 0
    X

    I write this but not acceptable with null case listed bellow. Does anyone can help? Thanks.
    Input:[10,5,15,null,null,6,20]
    Output:true
    Expected:false
    '''public class Solution {
    public boolean isValidBST(TreeNode root) {
    if (root==null) return true;
    boolean test1,test2;
    test1=root.left!=null? root.left.val<root.val:root.left==null;
    test2=root.right!=null? root.right.val>root.val:root.right==null;
    if(test1&&test2)
    return isValidBST(root.left)&&isValidBST(root.right);
    return false;

    }
    

    }'''


Log in to reply
 

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