用一个栈存储,元素,最小值,元素,最小值。。。。这样存储
import java.util.Stack;
public class Solution {
Stack<Integer> we = new Stack<Integer>();
int i;
public void push(int node) {
if(we.isEmpty()){
i = node;
we.push(i);
we.push(node);
}
else{
if(i > node){
i = node;
}
we.push(i);
we.push(node);
}
}
public void pop() {
we.pop();
we.pop();
int op = we.pop();
int io = we.pop();
we.push(io);
we.push(op);
i = io;
}
public int top() {
return we.peek();
}
public int min() {
int op = we.pop();
int io = we.pop();
we.push(io);
we.push(op);
return io;
}
}