class Solution {
public:
bool IsPopOrder(vector<int> pushV, vector<int> popV) {
if (pushV.size()==0||popV.size()==0||pushV.size()!=popV.size())
{
return false;
}
stack<int> my_stack;
int index(0);
for (auto i = 0; i < pushV.size();++i)
{
my_stack.push(pushV[i]);
while (my_stack.size()>0&&my_stack.top()==popV[index])
{
my_stack.pop();
index++;
}
}
if (my_stack.size()==0)
{
return true;
}
else
{
return false;
}
}
};
【剑指offer】题22:栈的压入、弹出序列
最新推荐文章于 2020-11-23 16:32:48 发布