class Solution {

public:

```
bool isValidBST(TreeNode* root) {
if (!root)
return true;
vector<TreeNode *> stack;
TreeNode *current = root, *last = NULL;
while (!stack.empty() || current)
{
if (current)
{
stack.push_back(current);
current = current->left;
}
else
{
current = *stack.rbegin();
stack.pop_back();
if (last && last->val >= current->val)
return false;
last = current;
current = current->right;
}
}
return true;
}
```

};