class Solution {
public:
bool isPost(vector<int> seq, int low, int high){
if (high<=low) return true;
int value = seq[high];
int index = high;
for (int i = low; i < high; i++){
if (seq[i]>value){
index = i;
break;
}
}
if (index<high){
for (int i = index+1; i < high; i++){
if (seq[i]<value) return false;
}
return isPost(seq, low, index-1) && isPost(seq, index, high-1);
}
return true;
}
bool VerifySquenceOfBST(vector<int> seq) {
int len = seq.size();
if (!len) return false;
return isPost(seq, 0, len-1);
}
};