class MinStack {
private Stack<Integer> data;
private Stack<Integer> minStack;
/** initialize your data structure here. */
public MinStack() {
data = new Stack();
minStack = new Stack();
}
public void push(int x) {
data.push(x);
if(minStack.isEmpty()|| minStack.peek() >= x){
minStack.push(x);
}
}
public void pop() {
int x = data.pop();
if(!minStack.isEmpty() && minStack.peek().equals(x)){
minStack.pop();
}
}
public int top() {
return data.peek();
}
public int getMin() {
return minStack.peek();
}
}
08-24
162
11-10
276