二叉搜索树中的每个结点,其左子树的所有结点值都小于该结点值,右子树的所有结点值都大于该结点值。以下代码对给定的二叉树,判断其是否为合法的二叉搜索树(假设树中没有数值相等的元素),横线上应填写():
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def isValidBST(self, root: TreeNode) -> bool:
def helper(node, min_val, max_val):
if not node:
return True
————————————————————————————————————————————————
return False
return helper(node.left, min_val, node.val) and helper(node.right,node.val, max_val)
return helper(root, float('-inf'), float('inf'))