题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
#include <vector> class Solution { public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { vector<int> m(1,pushV[0]); int j=1; for(int i=0;i<popV.size();i++){ if(m.size()==0){ m.push_back(pushV[j]); j++; } while(m[m.size()-1]!=popV[i]&&j<=pushV.size()){ m.push_back(pushV[j]); j++; } if(m[m.size()-1]==popV[i]){ m.erase(m.end()-1); } else{ return false; } } return true; } };