题目链接:
https://leetcode.cn/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/description/?favorite=xb9nqhhg&orderBy=hot
代码:
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int>cnt;
int j=0;
for(int i=0;i<pushed.size();i++)
{
cnt.push(pushed[i]);
while(!cnt.empty()&&popped[j]==cnt.top())
{
j++;
cnt.pop();
}
}
if(cnt.empty())
{
return true;
}
else return false ;
}
};