public class Solution {
Stack<Integer> stack=new Stack<Integer>();//存放每次新来的元素
Stack<Integer> minStack=new Stack<Integer>();//存放当前最小值的栈
public void push(int node) {
stack.push(node);
if(minStack.isEmpty()||node<minStack.peek()){
minStack.push(node);
}else{
minStack.push(minStack.peek());
//stack.peek()返回栈顶元素但是不弹出
//stack.pop()弹出栈顶元素
}
}
public void pop() {
stack.pop();
minStack.pop();
}
public int top() {
return stack.peek();
}
public int min() {
return minStack.peek();
}
}