//栈的压入 弹出序列
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();
}
};
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 次
全部评论
相关推荐

点赞 评论 收藏
分享