C++ 代码
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int> stk;
int n=pushed.size();
for(int i=0,j=0;i<n;i++){
stk.push(pushed[i]);
while(j<n&&!stk.empty()&&stk.top()==popped[j]){
stk.pop();
j++;
}
}
return stk.empty();
}
};