class Solution {
public:
bool IsPopOrder(vector<int> pushV,vector<int>& popV) {
if(pushV.size() == 0)
return true;
vector<int>::iterator it = pushV.begin();
bool flag = false;
for(int i = 0; i < pushV.size(); i++){
if(pushV[i] == popV[0]){
vector<int> tmp1(it+1, pushV.end());
popV.erase(popV.begin());
if(IsPopOrder(tmp1, popV)){
if(i != 0){
for(int j = i-1, k = 0; j >=0; j--){
if(pushV[j] != popV[k])
return false;
popV.erase(popV.begin());
}
}
return true;
}else return false;
}
it++;
}
return false;
}
};