当前位置:网站首页>剑指 Offer 30. 包含min函数的栈
剑指 Offer 30. 包含min函数的栈
2022-07-06 02:11:00 【anieoo】
solution:
用堆栈存储pair数据, first保存入栈元素,second保存最小值
class MinStack {
public:
/** initialize your data structure here. */
typedef pair<int,int> PII;
stack<PII> stk;
MinStack() {
}
//.first保存栈元素,.second保存最小值
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();
*/边栏推荐
- SSM 程序集
- Adapter-a technology of adaptive pre training continuous learning
- MySQL learning notes - subquery exercise
- 【机器人手眼标定】eye in hand
- Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
- 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)
- 阿裏測開面試題
- 好用的 JS 脚本
- Sword finger offer 38 Arrangement of strings
猜你喜欢

Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system

Computer graduation design PHP animation information website

Leetcode3, implémenter strstr ()

2 power view

数据工程系列精讲(第四讲): Data-centric AI 之样本工程

Redis如何实现多可用区?

vs code保存时 出现两次格式化

Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械

Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization

Pangolin Library: subgraph
随机推荐
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
RDD conversion operator of spark
阿裏測開面試題
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
RDD creation method of spark
机器学习训练与参数优化的一般过程 (讨论)
使用npm发布自己开发的工具包笔记
Concept of storage engine
[depth first search] Ji Suan Ke: Betsy's trip
Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
How to upgrade kubernetes in place
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
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
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
Leetcode3, implémenter strstr ()
Spark accumulator
1. Introduction to basic functions of power query
Initialize MySQL database when docker container starts
selenium 元素定位(2)
2022 edition illustrated network pdf