class Solution { public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { int len = pushV.size(); if(len==0) return false; int i=1,j=0; stack1.push(pushV[0]); while(i<=len && j<len){ if(stack1.top()!=popV[j]){ stack1.push(pushV[i]); i++; } else{ stack1.pop(); j++; } } if(stack1.empty()) return true; return false; } private: stack<int> stack1; };
原文:https://www.cnblogs.com/loyolh/p/12343094.html