包含min函数的栈 java
包含min函数的栈
http://www.nowcoder.com/questionTerminal/4c776177d2c04c2494f2555c9fcc1e49
import java.util.*; public class Solution { Stack stack = new Stack(); Stack minStack = new Stack(); int min=Integer.MAX_VALUE; public void push(int node) { stack.push(node); if(node<=min){ min=node; } minStack.push(min); } public void pop() { stack.pop(); minStack.pop(); } public int min() { return Integer.parseInt(minStack.peek().toString()); } }