思路:中序遍历这棵树,对当前节点和上一个节点做比较,如果当前节点小于或等于上一个节点,返回false
bool isValidBST(TreeNode* root) {
if(!root)return true;
stack<TreeNode*>st;
long long pre=0x8000000000000000;
while(root||!st.empty()){
while(root){
st.push(root);
root=root->left;
}
root=st.top();
st.pop();
if(root->val<=pre)return false;
pre=root->val;
root=root->right;
}
return true;
}