//借用辅助栈,注意:一定不能离开出栈序列和辅助栈顶元素,否则对于不符合出栈序列也可能导致辅助栈最后为空 class Solution { public: bool IsPopOrder(vector<int>& pushV, vector<int>& popV) { stack<int> st; auto pushvit = pushV.begin(); auto popvit = popV.begin(); while(pushvit != pushV.end()) { st.push(*pushvit); while(st.size()!=0 && *popvit == st.top())//用出栈的序列与辅助栈顶比较 { st.pop(); popvit++; } pushvit++; } return st.empty(); } };