当前位置:网站首页>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();
*/边栏推荐
- A basic lintcode MySQL database problem
- This time, thoroughly understand the deep copy
- Regular expressions: examples (1)
- Computer graduation design PHP college student human resources job recruitment network
- RDD partition rules of spark
- Leetcode3, implémenter strstr ()
- Competition question 2022-6-26
- Text editing VIM operation, file upload
- Thinking about the best practice of dynamics 365 development collaboration
- 更改对象属性的方法
猜你喜欢

Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle

Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns

Computer graduation design PHP part-time recruitment management system for College Students

Online reservation system of sports venues based on PHP

【机器人库】 awesome-robotics-libraries

leetcode3、實現 strStr()

2022 edition illustrated network pdf

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

Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022

A basic lintcode MySQL database problem
随机推荐
技术管理进阶——什么是管理者之体力、脑力、心力
[coppeliasim] efficient conveyor belt
[depth first search] Ji Suan Ke: Betsy's trip
The third level of C language punch in
Genius storage uses documents, a browser caching tool
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
0211 embedded C language learning
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
Selenium element positioning (2)
01. Go language introduction
从顶会论文看2022年推荐系统序列建模的趋势
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
Computer graduation design PHP enterprise staff training management system
SQL statement
MySQL index
Grabbing and sorting out external articles -- status bar [4]
机器学习训练与参数优化的一般过程 (讨论)