当前位置:网站首页>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();
*/边栏推荐
- PAT甲级 1033 To Fill or Not to Fill
- HDU_p1237_简单计算器_stack
- 机器学习训练与参数优化的一般过程 (讨论)
- Redis key operation
- The third level of C language punch in
- MySQL (IV) - transactions
- Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
- Method of changing object properties
- [coppeliasim] efficient conveyor belt
- 729. My schedule I / offer II 106 Bipartite graph
猜你喜欢

A basic lintcode MySQL database problem

在线怎么生成富文本

Multi function event recorder of the 5th National Games of the Blue Bridge Cup

500 lines of code to understand the principle of mecached cache client driver

零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器

Social networking website for college students based on computer graduation design PHP

Pangolin Library: subgraph

剑指 Offer 30. 包含min函数的栈

Computer graduation design PHP college student human resources job recruitment network

Virtual machine network, networking settings, interconnection with host computer, network configuration
随机推荐
Grabbing and sorting out external articles -- status bar [4]
[robot hand eye calibration] eye in hand
Computer graduation design PHP part-time recruitment management system for College Students
Adapter-a technology of adaptive pre training continuous learning
A basic lintcode MySQL database problem
Sword finger offer 12 Path in matrix
Competition question 2022-6-26
RDD creation method of spark
SSM assembly
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
2022 edition illustrated network pdf
FTP server, ssh server (super brief)
500 lines of code to understand the principle of mecached cache client driver
【clickhouse】ClickHouse Practice in EOI
Concept of storage engine
Keyword static
构建库函数的雏形——参照野火的手册
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share