递归
class Solution {
public:
bool dfs(vector<int>& postorder,int l,int r){
// cout<<"大循环"<<l<<" "<<r<<endl;
if(l>=r)return 1;
int i=l;
while(postorder[i]<postorder[r])i++;
int j=i;
while(postorder[i]>postorder[r])i++;
// cout<<"循环结果"<<j<<" "<<i<<endl;
bool flag1=dfs(postorder,l,j-1);
bool flag2=dfs(postorder,j,r-1);
return i==r&&flag1&&flag2;
}
bool verifyPostorder(vector<int>& postorder) {
return dfs(postorder,0,postorder.size()-1);
}
};