要求:rt
思路:整理一下
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int> s;
int po=0;
for(int num:pushed){
s.push(num);
while(!s.empty()&&po<popped.size()&&s.top()==popped[po]){
s.pop();
po++;
}
}
return s.empty();
}
};