当前位置:网站首页>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();
*/
边栏推荐
- Thinking about the best practice of dynamics 365 development collaboration
- Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
- I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
- Social networking website for college students based on computer graduation design PHP
- [solution] add multiple directories in different parts of the same word document
- leetcode-2. Palindrome judgment
- 机器学习训练与参数优化的一般过程 (讨论)
- [coppeliasim] 6-DOF path planning
- [depth first search notes] Abstract DFS
- RDD creation method of spark
猜你喜欢
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
2022 PMP project management examination agile knowledge points (8)
【无标题】数据库中一条查询SQL执行的过程
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
Structural theme model (I) STM package workflow
Redis如何实现多可用区?
0211 embedded C language learning
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
从顶会论文看2022年推荐系统序列建模的趋势
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
随机推荐
SSM assembly
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
[coppeliasim] efficient conveyor belt
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
The third level of C language punch in
剑指 Offer 30. 包含min函数的栈
PAT甲级 1033 To Fill or Not to Fill
Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
模板_快速排序_双指针
Xshell 7 Student Edition
SSM 程序集
一位博士在华为的22年
Prepare for the autumn face-to-face test questions
2022 PMP project management examination agile knowledge points (8)
怎么检查GBase 8c数据库中的锁信息?
Have a look at this generation
PHP campus movie website system for computer graduation design