```
class Solution {
public:
bool isValidBST(TreeNode* root) {
TreeNode* prev = NULL;
return validate(root, prev);
}
bool validate(TreeNode* node, TreeNode* &prev) {
if (node == NULL) return true;
if (!validate(node->left, prev)) return false;
if (prev != NULL && prev->val >= node->val) return false;
prev = node;
return validate(node->right, prev);
}
};
```

Update:

If we use in-order traversal to serialize a binary search tree, we can

get a list of values in ascending order. It can be proved with the

definition of BST. And here I use the reference of TreeNode

pointer`prev`

as a global variable to mark the address of previous node in the

list.“In-order Traversal”:

https://en.wikipedia.org/wiki/Tree_traversal#In-order

If you know what `INT_MAX`

or `INT_MIN`

is, then it is no excuse for your carelessness.