方法一:递归+分治
后续遍历: [[左] [右] [根]] 满足左<根<右
class Solution {
public:
bool isPos(vector<int>& postorder,int left,int right){
if(left>=right) return true;
int j = left;
while(j<right&&postorder[j]<postorder[right]){
j++;
}
for(int i = j;i<right;i++){
if(postorder[i]<postorder[right]) return false;
}
return isPos(postorder,left,j-1)&&isPos(postorder,j,right-1);
}
bool verifyPostorder(vector<int>& postorder) {
int size = postorder.size();
return isPos(postorder,0,size-1);
}
};