题解 | #栈的压入、弹出序列#C++辅助栈的简单实现

栈的压入、弹出序列

https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106

class Solution {
public:
    bool IsPopOrder(vector<int> pushV,vector<int> popV) {
        stack<int> st;
        int i = 0;
        for(auto e : pushV) {
            st.push(e);
            while(!st.empty() && st.top() == popV[i]) {
                st.pop();
                i++;
            }
        }
        return st.empty();
    }
};

全部评论

相关推荐

点赞 评论 收藏
转发
1 收藏 评论
分享
牛客网
牛客企业服务