I don't know why the solutios below is not right!


  • 0
    X
    // public boolean isValidBST(TreeNode root) {
    //     return check(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
    // }
    // private boolean check(TreeNode pNode, int pLeftVal, int pRightVal){
    //     if (null == pNode){
    //         return true;
    //     }
    //     return pNode.val > pLeftVal 
    //     && pNode.val < pRightVal 
    //     && check(pNode.left, pLeftVal, pNode.val) 
    //     && check(pNode.right, pNode.val, pRightVal);
    // }

  • 0
    W

    I am not sure about JAVA, but if Integer.MAX_VALUE is equal to the largest value int can be, then if root.val == Integer.MAX_VALUE, then this program return false.


Log in to reply
 

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