当前位置:网站首页>[leetcode stack and queue -- minimum stack] 155. Minimum stack
[leetcode stack and queue -- minimum stack] 155. Minimum stack
2022-07-22 16:37:00 【alone_ yue】
List of articles
Leetcode 155. Smallest stack
1. Problem description
2. Solution
Auxiliary stack min_stack and stack Store the same number of elements , Deposit is ,stack The corresponding element in push Minimum value after entering
class MinStack {
private LinkedList<Integer> stack;
private LinkedList<Integer> min_stack;
public MinStack() {
stack = new LinkedList<>();
min_stack = new LinkedList<>();
}
public void push(int val) {
stack.addLast(val);
if(min_stack.size()==0){
min_stack.addLast(val);
}else{
min_stack.addLast(Math.min(val, min_stack.getLast()));
}
}
public void pop() {
stack.removeLast();
min_stack.removeLast();
}
public int top() {
return stack.getLast();
}
public int getMin() {
return min_stack.getLast();
}
}
/** * Your MinStack object will be instantiated and called as such: * MinStack obj = new MinStack(); * obj.push(val); * obj.pop(); * int param_3 = obj.top(); * int param_4 = obj.getMin(); */
边栏推荐
- Kalman filter program of POTU PLC signal processing series
- 计算机网络之DNS面试题
- stm32使用各种传感器的教程
- 洛谷_P1112 波浪数_思维_进制 / 构造 / 枚举
- SFTP creation
- Informatics Olympiad all in one 1974: [16noip popularization group] palindrome date | Luogu p2010 [noip2016 popularization group] palindrome date
- How does the red team play
- Sort--排序中的 插入排序 和 希尔排序
- C# 上传图片至共享文件夹
- JVM memory model: classification and acquisition of class loaders
猜你喜欢
[SSM]SSM整合③(接口测试)
MP query criteria
Fastjson 代码执行 CVE-2022-25845
梅科尔工作室——HarmonyOS应用开发培训第三次作业
[leetcode string -- string subscript sorting] 6121. Query the number with the smallest k after cutting the number
JVM: parental delegation mechanism for class loading
Mock simulates data and initiates get and post requests (nanny level tutorials are sure to succeed)
Operation tutorial: UOB camera registers the detailed configuration of easycvr platform through gb28181 protocol
Lateral biting function provided by wisdom teeth
ftp服务器搭建部署与C#实现ftp文件的上传
随机推荐
ECCV 2022 | fix the performance damage of large targets caused by FPN: you should look at all objects
Lesson 3 shell syntax
Simplified writing of not like in MySQL
Lateral biting function provided by wisdom teeth
Interview questions about network related concepts
Methods of checking the ranking of papers and periodicals
[SSM]SSM整合①(整合配置)
ARC110E Shorten ABC
Transparent transmission of punctual atom Lora wireless serial port point-to-point communication and Its Precautions
Kalman filter program of POTU PLC signal processing series
嵌入式IDE原理 OpenOCD介绍 以及stlink如何连接stm32板子
【Leetcode字符串--字符串下标排序】6121.裁剪数字后查询第 K 小的数字
Rquestmapping's annotation function, annotation usage range, and attribute details of annotations
Memory management interview questions
JVM: parental delegation mechanism for class loading
CF1635F Closest Pair
JVM memory model: runtime data area and thread
This easy-to-use office network optimization tool is free
The competition of trillion market value public chain is white hot. Is there still a chance for the new public chain?
How to configure webrtc protocol for low latency playback on easycvr platform v2.5.0 and above?