Stack<Integer> stack= new Stack<>();
int min = Integer.MAX_VALUE;
public MinStack()
{
}
public void push(int x) {
if(x<=min) // 防止空栈出错
{
min = x;
}
stack.push(x);
}
public void pop() {
int peek = stack.pop();
if(peek == min)
min = stack.pop();
}
public int top() {
int peek = stack.pop();
return peek;
}
public int getMin() {
return min;
}
}