98. Validate Binary Search Tree
题目描述
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
Both the left and right subtrees must also be binary search trees.
|
|
题目大意
校验是否是二叉搜索树。
校验规则:
左子树的所有节点值都比根节点小;
右子树的所有节点值都比根节点大;
左子树和右子树也是二叉搜索树
解题思路
DFS,根据题目所述的规则进行判定即可。
代码
|
|