https://www.nowcoder.com/practice/a861533d45854474ac791d90e447bafd?tpId=13&tqId=11176&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
class Solution {
public:
bool VerifySquenceOfBST(vector<int> sequence) {
if (sequence.size() == 0) return false;
return check(sequence, 0, sequence.size()-1);
}
bool check(vector<int> &seq, int l, int r) {
if (l >= r) return true;
int root = seq[r];
int i = l-1;
for (; i < r; i++) {
if ( seq[i+1] >= root ) break;
}
for (int t = i+1; t < r; t++) {
if (seq[t] < root) return false;
}
return check(seq, l,i ) && check(seq, i+1, r-1);
}
};