剑指Offer20

package javaOffer;

import java.util.Stack;

public class o20_getMinStack {
Stack<Integer> stack1= new Stack<Integer>();
Stack<Integer> stack2= new Stack<Integer>();

public void push(int value) {
stack1.push(value);
if(stack2.empty())
stack2.push(value);
else if(value<=stack2.peek())
{
stack2.push(value);
}
}

public void pop() {
if(stack1.peek()==stack2.peek())
stack2.pop();
stack1.pop();

}

public int min() {
return stack2.peek();
}
}
原文地址:https://www.cnblogs.com/fanzihao/p/11144592.html