class Solution {
public:
bool IsPopOrder(vector<int> pushV,vector<int> popV) {
stack<int> s;
int index=0;
for(int i=0;i<popV.size();i++){
if(pushV[index]==popV[i]){
index++;
}else{
if(!s.empty()&&s.top()==popV[i]){
s.pop();
}else{
while(pushV[index]!=popV[i]){
s.push(pushV[index]);
index++;
}
index++;
}
}
}
return s.empty();
}
};