当前位置:网站首页>[sword finger offer] 42 Stack push in and pop-up sequence

[sword finger offer] 42 Stack push in and pop-up sequence

2022-07-07 10:15:00 percation

Through the tunnel
 Insert picture description here


The first question of rehabilitation training , I deeply feel that there is another dish , It's already very delicious

class Solution {
    
public:
    bool isPopOrder(vector<int> pushV,vector<int> popV) {
    
        if(popV.size() != pushV.size()) return false;
        stack<int> s;
        int idx = 0;
        for(int i = 0; i < pushV.size(); i++){
    
            s.push(pushV[i]);
            while(!s.empty() && (s.top() == popV[idx])){
    
                s.pop();
                idx++;
            }
        }
        if(s.empty() == true) return true;
        return false;
    }
};
原网站

版权声明
本文为[percation]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070746060706.html