I submit my code and got return as wrong answer since it does not pass case [0,-1]. It shows my output is false but it should be true. Then I run code by check customized case [0,-1]. It shows my output is true. Is there anything wrong?
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): global pre pre = None def isValidBST(self, root): """ :type root: TreeNode :rtype: bool """ global pre if (root == None): return True if ((not self.isValidBST(root.left)) or (pre != None and pre.val >= root.val)): return False pre = root if (not self.isValidBST(root.right)): return False return True
Please read the FAQ item no. 3.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.