当前位置:网站首页>栈的压入、弹出序列
栈的压入、弹出序列
2022-08-03 22:55:00 【老鱼37】

思路:
class Solution {
public:
bool IsPopOrder(vector<int> pushV,vector<int> popV) {
//辅助栈
stack<int>v;
if(pushV.size()!=popV.size())
{
return false;
}
//定位进栈、出栈、辅助栈的下标
int index=0;
int outdex=0;
while(outdex<popV.size())//出栈下标 条件
{
while(v.empty()||v.top()!=popV[outdex])//直到找到 不然一直压
{
if(index<pushV.size())
{
//压栈
v.push(pushV[index++]);
}
else
{
return false;
}
}
//找到之后 v出栈
v.pop();
outdex++;//+1
}
//验证完popV为正确的出栈顺序
return true;
}
};如有错误,多多指教
边栏推荐
- Conditional Statements for Shell Programming
- 2022-08-02 mysql/stonedb slow SQL-Q18 - memory usage surge analysis
- Kotlin - 扩展函数和运算符重载
- 易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
- How many way of calling a function?
- Scala基础【正则表达式、框架式开发原则】
- AOSP CameraLatencyHistogram的原理与使用
- 目标检测的国内外研究现状
- UVa 437 - The Tower of Babylon(白书)
- 电商秒杀系统
猜你喜欢

Network basic learning series four (network layer, data link layer and some other important protocols or technologies)

冰河又一MySQL力作出版(文末送书)!!

Walk the Maze BFS

ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例

complete binary tree problem

Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo

Embedded systems: overview

noip初赛

二叉搜索树解决落叶问题

Cloud platform construction solutions
随机推荐
电商秒杀系统
Testng监听器
如何创建一个Web项目
Another MySQL masterpiece published by Glacier (send the book at the end of the article)!!
Basic Concepts of Graphs
override学习(父类和子类)
【day6】类与对象、封装、构造方法
Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂
七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
P1996 约瑟夫问题
On the Qixi Festival of 2022, I will offer 7 exquisite confession codes, and at the same time teach you to quickly change the source code for your own use
Pytest learn-setup/teardown
[2022安恒夏令营] 5个小题
FinClip最易用的智能电视小程序
2022/8/3 考试总结
剑指offer第22题-链表中倒数第K个节点
Canvas App中点击图标生成PDF并保存到Dataverse中
Binary search tree to solve the fallen leaves problem
完全二叉树问题
SPOJ 2774 Longest Common Substring(两串求公共子串 SAM)