题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
class Solution { public: bool IsPopOrder(vector<int> pushV, vector<int> popV) { int size = pushV.size(); int push_idx = 0; int pop_idx = 0; stack<int> s; while (push_idx < size) { s.push(pushV[push_idx++]); while (!s.empty() && s.top() == popV[pop_idx]) { s.pop(); pop_idx++; } } return s.empty(); } };
2023-剑指-队列 + 栈 文章被收录于专栏
2023-剑指-队列 + 栈