当前位置:网站首页>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();
*/边栏推荐
- Regular expressions: examples (1)
- Leetcode3, implémenter strstr ()
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- Computer graduation design PHP campus restaurant online ordering system
- Using SA token to solve websocket handshake authentication
- Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
- Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
- Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
- Competition question 2022-6-26
- Prepare for the autumn face-to-face test questions
猜你喜欢

零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO

Using SA token to solve websocket handshake authentication
![抓包整理外篇——————状态栏[ 四]](/img/1e/2d44f36339ac796618cd571aca5556.png)
抓包整理外篇——————状态栏[ 四]

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

Redis string type

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据

Structural theme model (I) STM package workflow

Computer graduation design PHP campus restaurant online ordering system

技术管理进阶——什么是管理者之体力、脑力、心力
随机推荐
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
Use the list component to realize the drop-down list and address list
SSM assembly
UE4 - how to make a simple TPS role (I) - create a basic role
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Computer graduation design PHP campus restaurant online ordering system
PHP campus movie website system for computer graduation design
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
RDD partition rules of spark
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
Sword finger offer 12 Path in matrix
Computer graduation design PHP college classroom application management system
Social networking website for college students based on computer graduation design PHP
Redis string type
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
General process of machine learning training and parameter optimization (discussion)