双栈
包含min函数的栈
http://www.nowcoder.com/questionTerminal/4c776177d2c04c2494f2555c9fcc1e49
stack栈保存数据,如果新入栈的数据是当前最小的,则同时入minStack栈
将要出栈的数如果等于minStack栈顶的数,则两个栈同时出栈
public class Solution { private Stack<Integer> stack = new Stack<>(); private Stack<Integer> minStack = new Stack<>(); public void push(int node) { stack.push(node); if (minStack.empty() || node<=minStack.peek()){ minStack.push(node); } } public void pop() { if (!stack.empty()){ int pop = stack.pop(); if (pop==minStack.peek()){ minStack.pop(); } } } public int top() { return stack.peek(); } public int min() { return minStack.peek(); } }