class MinStack {
public:
/** initialize your data structure here. */
MinStack() {
}
void push(int x) {
if (!minStack.empty()) {
int m = (x < minStack.top()) ? x : minStack.top();
minStack.push(m);
} else {
minStack.push(x);
}
genStack.push(x);
}
void pop() {
minStack.pop();
genStack.pop();
}
int top() {
return genStack.top();
}
int getMin() {
return minStack.top();
}
private:
stack<int> minStack;
stack<int> genStack;
};
/**
* Your MinStack object will be instantiated and called as such:
* MinStack obj = new MinStack();
* obj.push(x);
* obj.pop();
* int param_3 = obj.top();
* int param_4 = obj.getMin();
*/