. - 力扣(LeetCode)
![](https://img-blog.csdnimg.cn/direct/53fabeaff14c482098e7c6b8336468c4.png)
![](https://img-blog.csdnimg.cn/direct/604fc69e4654481b87e9a5caa00b9f39.png)
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
bool isValidBST(TreeNode* root) {
inOrder(root);
return flag;
}
void inOrder(TreeNode* root) {
if(!root)
return;
inOrder(root->left);
if(root->val < pre) {
flag = false;
}
pre = root->val;
inOrder(root->right);
}
bool flag = true;
int pre = INT32_MIN;
};