当前位置:网站首页>栈的压入、弹出序列
栈的压入、弹出序列
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;
}
};
如有错误,多多指教
边栏推荐
猜你喜欢
Adobe是什么?
Analysys Analysis: The transaction scale of China's online retail B2C market in Q2 2022 will reach 2,344.47 billion yuan
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
"Digital Economy Panorama White Paper" Financial Digital User Chapter released!
Pytest learn-setup/teardown
complete binary tree problem
2022-08-03 oracle执行慢SQL-Q17对比
获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
Summary bug 】 【 Elipse garbled solution project code in Chinese!
AOSP CameraLatencyHistogram的原理与使用
随机推荐
ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例
藏宝计划TreasureProject(TPC)系统模式开发技术原理
Scala basics [regular expressions, framework development principles]
P1996 约瑟夫问题
start with connect by implements recursive query
node连接mysql数据库报错:Client does not support authentication protocol requested by server
ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
LabVIEW code generation error 61056
Boss: There are too many systems in the company, can you realize account interoperability?
一个函数有多少种调用方式?
Summary bug 】 【 Elipse garbled solution project code in Chinese!
log4j-slf4j-impl cannot be present with log4j-to-slf4j
Research status of target detection at home and abroad
redis持久化方式
电商秒杀系统
云平台建设解决方案
PowerMockup 4.3.4::::Crack
【day6】类与对象、封装、构造方法
Kotlin - extension functions and operator overloading
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.