题解 | #栈的压入、弹出序列#

栈的压入、弹出序列

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();
    }
//};

全部评论

相关推荐

11-06 16:50
门头沟学院 Java
用微笑面对困难:word打字比赛二等奖的我,也要来凑合凑合
点赞 评论 收藏
分享
10-30 16:31
重庆大学 Java
代码飞升:你说你善于学习,大家都会说。你说你是985,985会替你表达一切
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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