题目链接:98. 验证二叉搜索树 - 力扣(LeetCode)
即左边的小于根小于右边的,不仅仅是这样,根必须得比左子树的都要大,比右子树的都要小,因此对于每个节点都需要小于某个值大于某个值
class Solution {
public:bool assist(TreeNode *root, long long low, long long high) {if (root == nullptr)return true;if (root->val <= low || root->val >= high)return false;return assist(root->left, low, root->val) && assist(root->right, root->val, high);}bool isValidBST(TreeNode *root) {return assist(root, LONG_LONG_MIN, LONG_LONG_MAX);}
};