模拟法
用栈
https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/solution/mian-shi-ti-31-zhan-de-ya-ru-dan-chu-xu-lie-mo-n-2/
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int>stk;
int i=0;
for(int num:pushed){
stk.push(num);
while(!stk.empty()&&stk.top()==popped[i]){
stk.pop();
i++;
}
}
return stk.empty();
}
};