← 返回 bytedance 的题目列表Validate Binary Search Tree in Binary Tree
类型:online_judge
bytedance
Given a binary tree, determine if it is a valid binary search tree (BST).
A valid BST is defined as follows: For every node in the tree, all node values in its left subtree are less than the node's value, and all node values in its right subtree are greater than the node's value.
The binary tree node definition is as follows:
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
Input-Output Example
Input:
root = [2,1,3]
Output:
True
Input:
root = [5,1,4,null,null,3,6]
Output:
False
Please implement an algorithm to achieve this functionality.
Example
Input
root = [2,1,3]