class Solution { public: bool isValidBST(TreeNode *root) { stack<TreeNode *>s; TreeNode *p=root; int pre=INT_MIN; while(p||!s.empty()) { while(p) { s.push(p); p=p->left; } if(!s.empty()) { p=s.top(); s.pop(); if(p->val<=pre)return false; pre=p->val; p=p->right; } } return true; } };