当前位置:网站首页>栈的压入、弹出序列
栈的压入、弹出序列
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;
}
};如有错误,多多指教
边栏推荐
- RPA power business automation super order!
- log4j-slf4j-impl cannot be present with log4j-to-slf4j
- 一个函数有多少种调用方式?
- utils timer
- [2022安恒夏令营] 5个小题
- BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
- PowerMockup 4.3.4::::Crack
- 2022-08-03 oracle执行慢SQL-Q17对比
- HCIP BGP实验报告
- Walk the Maze BFS
猜你喜欢
![Scala basics [regular expressions, framework development principles]](/img/be/6531f32494b8516cd7031223d14bb2.png)
Scala basics [regular expressions, framework development principles]

Live Preview | Build Business Intelligence, Quickly Embrace Financial Digital Transformation

V8中的快慢数组(附源码、图文更易理解)

【day6】类与对象、封装、构造方法
![[N1CTF 2018] eating_cms](/img/09/3599d889d9007eb45c6eab3043f0c4.png)
[N1CTF 2018] eating_cms

易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元

禾匠编译错误记录

The salary of soft testers at each stage, come to Kangkang, how much can you get?

Embedded Systems: Clocks

生成器版和查看器版有什么区别?
随机推荐
Unity2021发布WebGL雾效消失问题
BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
rosbridge-WSL2 && carla-win11
直播预告 | 构建业务智联,快速拥抱财务数字化转型
Embedded Systems: Clocks
complete binary tree problem
物联网新零售模式,引领购物新潮流
HCIP BGP实验报告
rosbridge-WSL2 && carla-win11
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
使用tf.image.resize() 和tf.image.resize_with_pad()调整图像大小
PowerMockup 4.3.4::::Crack
Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne
设置工作模式与环境(下):探查和收集信息
软件测试内卷严重,如何提升自己的竞争力呢?
Create function report error, prompting DECLARE definition syntax problem
3D 语义分割——2DPASS
OPC UA 与IEC61499 深度融合(1)
113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself
完全二叉树问题