class Solution {
public:
bool VerifySquenceOfBST(vector<int> s) {
int n = s.size();
if (n==0)return 0;
int l = 0, r = n - 1;
return check(s, l, r);
}
bool check (vector<int>&sq, int l, int r) {
if (l >= r) return 1;
int root = sq[r];
int j = r - 1;
while (j>= l && sq[j] > root) j --;
for (int i = l; i <= j; i ++) {
if (sq[i] > root) return 0;
}
return check(sq, l, j) && check(sq, j + 1, r - 1);
}
};

https://www.nowcoder.com/practice/a861533d45854474ac791d90e447bafd?tpId=13&tqId=23289&ru=%2Fpractice%2F508378c0823c423baa723ce448cbfd0c&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&sourceUrl= 问题结构:性质题

我们可以确定最后一个r一定是根节点,然后我们可以划分左子树和右子树判断就行了