题解 | 栈的压入弹出序列
栈的压入、弹出序列
http://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
利用辅助栈
public:
bool IsPopOrder(vector<int> pushV,vector<int> popV) {
stack<int> stackV;
int i=0,j=0;
stackV.push(pushV[0]);
while(i<pushV.size()&&j<popV.size()){
if(stackV.empty()){
i++;
stackV.push(pushV[i]);
}
if(stackV.top()!=popV[j]){
i++;
stackV.push(pushV[i]);
continue;
}
stackV.pop();
j++;
}
return stackV.empty();
}
};