题目链接:https://leetcode-cn.com/problems/validate-stack-sequences/
题目如下:
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
if(pushed.size()!=popped.size()) return false;
if(pushed.size()==0&&popped.size()==0) return true;
stack<int> stk;
int index=0;
for(auto e:pushed){
stk.push(e);
while(stk.size()!=0&&stk.top()==popped[index]){
stk.pop();
index++;
}
}
return stk.size()==0;
}
};