1
# Runtime: 89 ms (Top 18.35%) | Memory: 16.5 MB (Top 80.77%)2
# Definition for a binary tree node.4
# def __init__(self, val=0, left=None, right=None):9
def isValidBST(self, root: Optional[TreeNode]) -> bool:11
def valid(node, left, right):12
if not node: # checking node is none15
node.val > left and node.val < right16
): # checking the left value is less than node and right value is greater than node18
return valid(node.left, left, node.val) and valid(19
node.right, node.val, right20
) # recursively calling left child and right child and returing the result True if both are true else False23
root, float("-inf"), float("inf")24
) # calling recursive function to check