提交 1920f4fd 编写于 作者: A AbelEthan

1.添加155題案例代碼,以及测试案例

上级 55720564
......@@ -14,10 +14,14 @@
*.jar
*.war
*.nar
*.iml
*.ear
*.zip
*.tar.gz
*.rar
.idea
target/
out
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
package com.aen.leetcode;
/**
* Title: {@link com.aen.leetcode}
* Description:
*
* @author 谭 tmn
* @email AbelEthan@126.com
* @date 20-10-16 上午11:56
*/
public class MinStack {
private int top;
private int min;
private int maxSize;
private int[] data;
public MinStack() {
top = -1;
min = Integer.MAX_VALUE;
maxSize = 100000;
data = new int[maxSize];
}
public void push(int x) {
if (x < min) {
data[++top] = min;
min = x;
}
data[++top] = x;
}
public void pop() {
if (min == data[top]) {
min = data[--top];
}
--top;
}
public int top() {
return data[top];
}
public int getMin() {
return min;
}
}
package com.aen.leetcode;
/**
* Title: {@link com.aen.leetcode}
* Description:
*
* @author 谭 tmn
* @email AbelEthan@126.com
* @date 20-10-16 下午1:51
*/
public class MinStackTest {
public static void main(String[] args) {
MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
int min = minStack.getMin();
System.out.println(min);
minStack.pop();
int top = minStack.top();
System.out.println(top);
int min1 = minStack.getMin();
System.out.println(min1);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册