当前位置:网站首页>31. stack push in and pop-up sequence
31. stack push in and pop-up sequence
2022-06-12 05:18:00 【Be your goat】
The finger of the sword Offer 31. Pressure into the stack 、 Pop-up sequence
Ideas : Stack simulation
- initialization : Auxiliary stack stack, Pop up the index of the sequence i
- Traverse the stack sequence , Each element is marked as num:
- Elements num Push ;
- Loop out the stack : if stack Top element of = Pop up sequence elements popped[i], Perform stack out and i++
- Return value : if stack It's empty , Then this pop-up sequence is legal
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
stack<int> stk;
int i=0;
for(int n:pushed){
stk.push(n);
while(stk.size()&&stk.top()==popped[i]){
stk.pop();
++i;
}
}
return stk.empty();
}
};
Time complexity O(n)
Spatial complexity O(n)
边栏推荐
- Normalized vegetation index (NDVI) data, NPP data, GPP data, evapotranspiration data, vegetation type data, ecosystem type distribution data
- Minigui3 runs on Hisilicon hi3520d/hi3531 platform
- Uview customer management JS
- Codec of ASoC framework driven by alsa
- Alsa architecture application aplay and amixer call relationship (from application layer to kernel driver)
- LabVIEW about TDMS and Binary Storage Speed
- Gao Xiang slam14 notes on three Lie groups and Lie algebra
- Development of video preview for main interface of pupanvr-ui
- 【cjson】根节点注意事项
- Chapter 1
猜你喜欢

4.3 模拟浏览器操作和页面等待(显示等待和隐式等待、句柄)

Serial port oscilloscope_ port_ Setup of plotter secondary development environment (including QT setup)

2022-02-28 WPF upper computer 126 understand mqtt

1008 color classification

Redis learning notes (continuously updating)

Map coordinate conversion of Baidu map API

Accumulated temperature spatial distribution data, temperature distribution data, sunshine data, rainfall distribution, solar radiation data, surface runoff data, land use data, NPP data, NDVI data

Ubunt 20.04 uses CDROM or ISO as the installation source

How to deploy PostgreSQL as a docker container

How to deploy dolphin scheduler Apache dolphin scheduler 1.2.0 in cdh5.16.2
随机推荐
Index fund summary
February 19, 2022 [Nolan] Nolan resurrected? Change · Nolan [soul orchid] can be connected to XDD / silly girl
Design of a simple embedded web service application
Layer sublayer assigns values to the page elements of the parent layer to achieve the effect of transferring values to the page of the parent layer
Fundamentals of intensive learning openai gym environment construction demo
2022“高考记忆” 已打包完成,请查收!
【cjson】根节点注意事项
Esp32-who face detection
1008 color classification
Parallelization of accelerated training tf data. Dataset generator
Computer network connected but unable to access the Internet
Servlet core
National land use data of 30m precision secondary classification
ShanMeng and Beijing Adoption Day start NFT digital collection public offering
Spatial distribution data of China's tertiary watershed / national new area distribution data /npp net primary productivity data / spatial distribution data of vegetation cover / land use data /ndvi d
Radiometric calibration and atmospheric correction of sentry 2 L1C multispectral data using sen2cor
Detailed usage of vim editor
Force/release learning and sorting in IC Verification (6) research on the influence of wire type signals
Applet pull-down load refresh onreachbottom
MySQL Linux Installation mysql-5.7.24