当前位置:网站首页>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();
*/
边栏推荐
- [robot hand eye calibration] eye in hand
- 安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
- 【社区人物志】专访马龙伟:轮子不好用,那就自己造!
- Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
- Paper notes: limit multi label learning galaxc (temporarily stored, not finished)
- PAT甲级 1033 To Fill or Not to Fill
- Global and Chinese market of commercial cheese crushers 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- VIM usage guide
猜你喜欢
Spark accumulator
PHP campus movie website system for computer graduation design
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Structural theme model (I) STM package workflow
[depth first search notes] Abstract DFS
Numpy array index slice
使用npm发布自己开发的工具包笔记
2022 PMP project management examination agile knowledge points (8)
随机推荐
【无标题】数据库中一条查询SQL执行的过程
【coppeliasim】高效传送带
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
抓包整理外篇——————状态栏[ 四]
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
构建库函数的雏形——参照野火的手册
Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
The third level of C language punch in
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
SQL statement
RDD partition rules of spark
Adapter-a technology of adaptive pre training continuous learning
[robot hand eye calibration] eye in hand
Using SA token to solve websocket handshake authentication
Use Scrollview and tabhost to realize vertical scrollbars and tabs
Computer graduation design PHP enterprise staff training management system
Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
Campus second-hand transaction based on wechat applet