class Solution
{
public
:
bool
isValidBST(TreeNode
* root
) {
if(!root
)
return true
;
stack
<TreeNode
*> stack
;
TreeNode
* cur
= root
;
long value
= LONG_MIN
;
while(cur
|| !stack
.empty()){
while(cur
){
stack
.push(cur
);
cur
=cur
->left
;
}
cur
= stack
.top();
stack
.pop();
if(cur
->val
<=value
) return false
;
value
= cur
->val
;
cur
=cur
->right
;
}
return true
;
}
};
转载请注明原文地址: https://win8.8miu.com/read-13832.html