class Solution {
public:
bool IsPopOrder(vector<int> pushV,vector<int> popV) {
int len = pushV.size();
int i = 0;
int j = 0;
stack<int> s;
while(i < len && j < len){
//不相等
if(pushV[i] != popV[j]){
s.push(pushV[i]);
}
else{
++j;
}
++i;
}
while(s.empty() != 1){
int top = s.top();
if(top != popV[j]){
return false;
}
++j;
s.pop();
}
return true;
}
};
栈的压入和弹出序列
最新推荐文章于 2023-02-20 09:12:06 发布