题解 | #判断是不是二叉搜索树#
判断是不是二叉搜索树
https://www.nowcoder.com/practice/a69242b39baf45dea217815c7dedb52b
bool isValidBSTHelper(struct TreeNode* node, long long lower, long long upper) { if (node == NULL) return true; if (node->val <= lower || node->val >= upper) return false; return isValidBSTHelper(node->left, lower, node->val) && isValidBSTHelper(node->right, node->val, upper); } bool isValidBST(struct TreeNode* root ) { return isValidBSTHelper(root, -10000000000, 10000000000); }