1 模拟栈法
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
int len = pushed.size();
stack<int>st;
int i=0;
while(i<len)
{
st.push(pushed[i]);
while(st.size()!=0 && st.top() == popped[0]) //若匹配,一直出栈
{
popped.erase(popped.begin());
st.pop();
}
i++;
}
if(st.size()==0)
return true;
else
return false;
}
};