题解 | 栈的压入、弹出序列
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
class Solution { public: //模拟压栈出栈的顺序 bool IsPopOrder(vector<int>& pushV, vector<int>& popV) { stack<int> stk; int i=0; int n = popV.size(); for(int a:pushV){ stk.push(a); while( !stk.empty() && i<= n && stk.top() == popV[i] ){ stk.pop(); ++i; } } return (i == n)? true:false; } };