```
class MinStack {
public:
//1.维护一个单调栈
//2.对于第一个元素 min为empty所以我们需要判断一下empty直接放入
int min;
stack[HTML_REMOVED]stk;
stack[HTML_REMOVED]min_;
/* initialize your data structure here. /
MinStack() {
}
void push(int x) {
stk.push(x);
if(min_.empty()||x<=min_.top())
min_.push(x);
}
void pop() {
if(stk.top()==min_.top())
min_.pop();
stk.pop();
}
int top() {
return stk.top();
}
int getMin() {
return min_.top();
}
};
/*
* 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();
/
```