C++ 代码
class Solution {
public:
vector<int> s;
bool verifySequenceOfBST(vector<int> sequence) {
s = sequence;
return fun(0,s.size()-1);
}
bool fun(int l, int r){
if(r-l <= 1)return true;
int mid = s[r];
//int flag = 0;
for(int i = l ; i < r; i++){
if(s[i] < mid) continue;
else{//s[i] > mid
for(int j = i ; j < r; j++){
if(s[j] < mid){
return false;
}
}
return fun(l,i-1)&&fun(i,r-1);
}
}
return fun(l,r-1);
}
};