数据结构:树🌲
时间复杂度:O(n)
空间复杂度:O(n)
代码实现:
class Solution:def isValidBST(self, root: Optional[TreeNode]) -> bool:def dfs(root, l, r):if not root:return Trueif not l < root.val < r:return Falsereturn dfs(root.left, l, root.val) and dfs(root.right, root.val, r)return dfs(root, -10e9, 10e9)