题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
#include<iostream> #include<algorithm> #include<vector> #include<stack> using namespace std; //class Solution { //public: bool IsPopOrder(vector<int> pushV, vector<int> popV) { stack<int> s; int j = 0; for (int i = 0; i < pushV.size(); i++) { s.push(pushV[i]); while (s.size() > 0 && s.top() == popV[j]) { j++; s.pop(); } } return s.empty(); } //};