当前位置:网站首页>剑指 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();
*/边栏推荐
- Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
- How to set an alias inside a bash shell script so that is it visible from the outside?
- 论文笔记: 图神经网络 GAT
- 安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
- Gbase 8C database upgrade error
- 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
- PHP campus movie website system for computer graduation design
- Competition question 2022-6-26
- Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
- Leetcode3. Implement strstr()
猜你喜欢

【clickhouse】ClickHouse Practice in EOI

Computer graduation design PHP enterprise staff training management system

Jisuanke - t2063_ Missile interception

How does redis implement multiple zones?
![[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice](/img/3a/63f3e89ddf84f23f950ed9620b4405.jpg)
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice

在线怎么生成富文本

NumPy 数组索引 切片

Redis list

MySQL index

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
随机推荐
[coppeliasim] 6-DOF path planning
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
Using SA token to solve websocket handshake authentication
Use Scrollview and tabhost to realize vertical scrollbars and tabs
[eight part essay] what is the difference between unrepeatable reading and unreal reading?
阿里测开面试题
I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
Use the list component to realize the drop-down list and address list
2022 PMP project management examination agile knowledge points (8)
SSM 程序集
[depth first search notes] Abstract DFS
[solution] every time idea starts, it will build project
Leetcode sum of two numbers
Redis list
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
leetcode-2.回文判断
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
Computer graduation design PHP enterprise staff training management system