题目链接:https://www.acwing.com/problem/content/description/40/
题目如下:
class Solution {
public:
bool isPopOrder(vector<int> pushV,vector<int> popV) {
//两种情况的特判
if(pushV.size()==0&&popV.size()==0) return true;
if(pushV.size()!=popV.size()) return false;
stack<int> stk;
int index=0;
for(int i=0;i<pushV.size();i++){
stk.push(pushV[i]);
while(!stk.empty()&&stk.top()==popV[index]){//只要栈中还有元素,遇到相同的就弹出,遇不到相同的存入
stk.pop();
++index;
}
}
return stk.empty();
}
};