1 Star 0 Fork 0

表情扭曲 / leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc155.java 1009 Bytes
一键复制 编辑 原始数据 按行查看 历史
liu13 提交于 2019-01-05 15:23 . 20190105
package code;
/*
* 155. Min Stack
* 题意:设计一个栈,这个栈有一个getmin方法
* 难度:Easy
* 分类:Stack, Design
* 思路:每次替换最小值时,把当前最小值入栈用以记录,以便之后更新最小值
* Tips:
*/
import java.util.Stack;
public class lc155 {
class MinStack {
Stack<Integer> st;
int min = Integer.MAX_VALUE;
/** initialize your data structure here. */
public MinStack() {
this.st = new Stack<Integer>();
}
public void push(int x) {
if(x<=min){ //别忘了=
st.push(this.min);
this.min = x;
}
st.push(x);
}
public void pop() {
int x = st.pop();
if(x==this.min){
this.min = st.pop();
}
}
public int top() {
return st.peek();
}
public int getMin() {
return this.min;
}
}
}
1
https://gitee.com/abfantasy/leetcode.git
git@gitee.com:abfantasy/leetcode.git
abfantasy
leetcode
leetcode
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891