当前位置:网站首页>Sword finger offer 30 Stack containing min function
Sword finger offer 30 Stack containing min function
2022-07-06 02:20:00 【anieoo】
Original link : The finger of the sword Offer 30. contain min Function of the stack
solution:
Store with stack pair data , first Save the stacked elements ,second Save the minimum
class MinStack {
public:
/** initialize your data structure here. */
typedef pair<int,int> PII;
stack<PII> stk;
MinStack() {
}
//.first Save stack elements ,.second Save the minimum
void push(int x) {
if(stk.empty() || x < stk.top().second) {
stk.push({x, x});
return;
}
stk.push({x, stk.top().second});
}
void pop() {
stk.pop();
}
int top() {
return stk.top().first;
}
int min() {
return stk.top().second;
}
};
/**
* Your MinStack object will be instantiated and called as such:
* MinStack* obj = new MinStack();
* obj->push(x);
* obj->pop();
* int param_3 = obj->top();
* int param_4 = obj->min();
*/
边栏推荐
- SPI communication protocol
- 构建库函数的雏形——参照野火的手册
- Multi function event recorder of the 5th National Games of the Blue Bridge Cup
- MySQL (IV) - transactions
- [depth first search] Ji Suan Ke: Betsy's trip
- 使用npm发布自己开发的工具包笔记
- PHP campus financial management system for computer graduation design
- MySQL index
- Keyword static
- Black high-end responsive website dream weaving template (adaptive mobile terminal)
猜你喜欢
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
PHP campus movie website system for computer graduation design
Redis list
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
PHP campus financial management system for computer graduation design
Computer graduation design PHP college classroom application management system
Using SA token to solve websocket handshake authentication
Black high-end responsive website dream weaving template (adaptive mobile terminal)
Derivation of Biot Savart law in College Physics
随机推荐
MySQL (IV) - transactions
VIM usage guide
[coppeliasim] efficient conveyor belt
构建库函数的雏形——参照野火的手册
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
2022 edition illustrated network pdf
Pangolin Library: subgraph
使用npm发布自己开发的工具包笔记
Lecture 4 of Data Engineering Series: sample engineering of data centric AI
Text editing VIM operation, file upload
[depth first search] Ji Suan Ke: Betsy's trip
2022年版图解网络PDF
FTP server, ssh server (super brief)
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
Gbase 8C database upgrade error
Computer graduation design PHP part-time recruitment management system for College Students
Computer graduation design PHP campus restaurant online ordering system
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
The third level of C language punch in