当前位置:网站首页>栈的压入、弹出序列
栈的压入、弹出序列
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;
}
};
如有错误,多多指教
边栏推荐
- "Digital Economy Panorama White Paper" Financial Digital User Chapter released!
- CAS:178744-28-0,mPEG-DSPE,DSPE-mPEG,甲氧基-聚乙二醇-磷脂酰乙醇胺供应
- Golang Chapter 2: Program Structure
- Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
- 2022-08-02 mysql/stonedb慢SQL-Q18-内存使用暴涨分析
- 云计算国内外发展现状
- Binary search tree to solve the fallen leaves problem
- Golang第二章:程序结构
- 冰河又一MySQL力作出版(文末送书)!!
- 软测人每个阶段的薪资待遇,快来康康你能拿多少?
猜你喜欢
113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself
HCIP BGP实验报告
encapsulation, package, access modifier, static variable
Scala basics [regular expressions, framework development principles]
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
软测人每个阶段的薪资待遇,快来康康你能拿多少?
Scala基础【正则表达式、框架式开发原则】
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
FinClip最易用的智能电视小程序
随机推荐
Makefile
Canvas App中点击图标生成PDF并保存到Dataverse中
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
Cloud platform construction solutions
生成器版和查看器版有什么区别?
Embedded systems: overview
start with connect by implements recursive query
雅思大作文写作模版
Adobe是什么?
Kotlin - extension functions and operator overloading
ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
软件测试内卷严重,如何提升自己的竞争力呢?
Scala basics [regular expressions, framework development principles]
Kotlin - 扩展函数和运算符重载
Interpretation of ML: A case of global interpretation/local interpretation of EBC model interpretability based on titanic titanic rescued binary prediction data set using interpret
rosbridge-WSL2 && carla-win11
Click the icon in Canvas App to generate PDF and save it to Dataverse
Deep integration of OPC UA and IEC61499 (1)