import java.util.*;
import java.util.Stack;
public class Solution {
Stack<Integer> s1 = new Stack<Integer>();
//存最小的元素
Stack<Integer> s2 = new Stack<Integer>();
public void push(int node) {
s1.push(node);
if(s2.isEmpty() || s2.peek() > node){
s2.push(node);
}else{
s2.push(s2.peek());
}
}
public void pop() {
s1.pop();
s2.pop();
}
public int top() {
return s1.peek();
}
public int min() {
return s2.peek();
}
}
用了两个Stack,s2存最小的元素,s1、s2同时push()、pop()