您的位置:首页 > Web前端

【剑指offer】题22:栈的压入、弹出序列

2017-07-02 11:05 387 查看
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;
}
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: