最小栈
class MinStack{ private Stack<Integer> dataStack = new Stack<Integer>(); private Stack<Integer> minStack = new Stack<Integer>(); public void push(int x){ dataStack.add(x); if(minStack.isEmpty() || minStack.peek()>=x){ minStack.add(x); }else{ minStack.add(minStack.peek()); } } public void pop(){ dataStack.pop(); minStack.pop(); } public int peek(){ return dataStack.peek(); } public int getMin(){ return minStack.peek(); } }