当前位置:网站首页>Detailed explanation of minimum stack
Detailed explanation of minimum stack
2022-06-30 02:27:00 【Evil_ boy__】
Introduction to minimum stack :
Minimum stack is an algorithm idea , Can be in O(1) Get the minimum value of the whole stack in the time complexity of
Minimum stack idea :
We need two stacks , One is the main stack , One is the smallest stack , If a number enters the main stack , Then we compare this number with the top element of the smallest stack , If it is smaller than the top element of the smallest stack , Then this number will be put into the minimum stack , Otherwise, put the top element of the minimum stack back into the minimum stack

subject : Smallest stack
link :155. Smallest stack - Power button (LeetCode)
Title Description :

Input :
Output :
explain :
Code :
class MinStack {
public:
stack<int> st, stt;
MinStack() {
}
void push(int val) {
st.push(val);
if(stt.empty()){
stt.push(val);
}else{
if(stt.top() > val){
stt.push(val);
}else{
stt.push(stt.top());
}
}
}
void pop() {
st.pop();
stt.pop();
}
int top() {
return st.top();
}
int getMin() {
return stt.top();
}
};
/**
* Your MinStack object will be instantiated and called as such:
* MinStack* obj = new MinStack();
* obj->push(val);
* obj->pop();
* int param_3 = obj->top();
* int param_4 = obj->getMin();
*/
边栏推荐
- Est - ce que la bourse en ligne est sécurisée? Dois - je ouvrir un compte pour la spéculation boursière?
- Merge sort
- Four, forty, fourhundred swatches
- Internet Crime Complaint Center reports an increase in DDoS Attacks
- 網上炒股安全麼?炒股需要開戶嗎?
- 什么是证书透明度CT?如何查询CT logs证书日志?
- JS advanced -es6 syntax
- 希尔排序
- 【干货分享】最新WHQL徽标认证申请流程
- How vscode debugs into standard library files / third-party package source code
猜你喜欢

Creating exquisite skills in maker Education

How vscode debugs into standard library files / third-party package source code

如何预防钓鱼邮件?S/MIME邮件证书来支招

五个最便宜的通配符SSL证书品牌

IBM websphere通道联通搭建和测试

Differences among digicert, SECTIONO and globalsign code signing certificates

论文回顾:Playful Palette: An Interactive Parametric Color Mixer for Artists

CTF入门学习(Web方向)

Realization of a springboard machine

Le Code autojs peut - il être chiffré? Oui, présentation des techniques de chiffrement autojs
随机推荐
DHU programming exercise
SSL证书七大常见错误及解决方法
桶排序
Realization of a springboard machine
[论]【DSTG】Dynamic SpatiotemporalGraph Convolutional Neural Networks for Traffic Data Imputation
FDA ESG regulation: digital certificate must be used to ensure communication security
Global communication infrastructure faces apt, robotics and DDoS; The weakest mobile network
Alphassl digital certificate
Bucket sort
DDoS threat situation gets worse
如何预防钓鱼邮件?S/MIME邮件证书来支招
Creating exquisite skills in maker Education
FDA邮件安全解决方案
VScode如何Debug(调试)进入标准库文件/第三方包源码
实现VS每次只运行一个源文件
Heap sort
2022年7月深圳地区CPDA数据分析师认证
C language pivot_ Invalid argument error resolution for root
FDA mail security solution
走进江苏作家诗人胭脂茉莉|世界读书日