//栈的压入 弹出序列
class Solution {
public:
    bool IsPopOrder(vector<int> pushV,vector<int> popV) {
        if(pushV.size() != popV.size()) return false;
        
        int i = 0;
        stack<int> stk;
        for(auto x:pushV)
        {
            stk.push(x);
            while( stk.size() && stk.top()==popV[i])
            {
                stk.pop();
                i++;
            }
        }
        
        return stk.empty();
    }
};
2020-05-08
在牛客打卡16天,今天学习:刷题 2 道/代码提交 2 次
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务