classMinStack{ classMinNode{ int min, val; publicMinNode(int min, int val){ this.min = min; this.val = val; } } Stack<MinNode> st; int min; publicMinStack(){ st = new Stack<MinNode>(); min = Integer.MAX_VALUE; } publicvoidpush(int x){ if(x <= min) min = x; MinNode t = new MinNode(min, x); st.push(t); } publicvoidpop(){ if(!st.isEmpty()){ MinNode t = st.pop(); //need to reset the min to what it was before we saw this value if(!st.isEmpty()) min = st.peek().min; else min = Integer.MAX_VALUE; } } publicinttop(){ if(st.isEmpty()) return -1; return st.peek().val; } publicintgetMin(){ if(st.isEmpty()) return -1; return st.peek().min; } }