当前位置:网站首页>栈的压入、弹出序列
栈的压入、弹出序列
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;
}
};
如有错误,多多指教
边栏推荐
- utlis thread pool
- utils timer
- CAS: 178744-28-0, mPEG-DSPE, DSPE-mPEG, methoxy-polyethylene glycol-phosphatidylethanolamine supply
- The development status of cloud computing at home and abroad
- pikachu Over permission
- 伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
- UVa 437 - The Tower of Babylon(白书)
- Create function report error, prompting DECLARE definition syntax problem
- Software testing is seriously involution, how to improve your competitiveness?
- Optimize the query (work in progress)
猜你喜欢
随机推荐
With the rise of concepts such as metaverse and web3.0, many digital forms such as digital people and digital scenes have begun to appear.
Embedded systems: overview
Golang第二章:程序结构
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
ML's yellowbrick: A case of interpretability (threshold map) for LoR logistic regression model using yellowbrick based on whether Titanic was rescued or not based on the two-class prediction dataset
走迷宫 BFS
HCIP BGP实验报告
AOSP CameraLatencyHistogram的原理与使用
完全二叉树问题
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
What is memoization and what is it good for?
The principle and use of AOSP CameraLatencyHistogram
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
Conditional Statements for Shell Programming
软测人每个阶段的薪资待遇,快来康康你能拿多少?
Embedded Systems: GPIO
[N1CTF 2018] eating_cms
Republish the lab report
golang写的存储引擎,基于b+树,mmap
Another MySQL masterpiece published by Glacier (send the book at the end of the article)!!