二叉搜索树中的每个结点,其左子树的所有结点值都小于该结点值,右子树的所有结点值都大于该结点
值。以下代码对给定的整数数组(假设数组中没有数值相等的元素),构造一个对应的二叉搜索树,横线上应填写(
):
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'))