class MinStack {
public:
/** initialize your data structure here. */
// 单调栈方法
MinStack() {
}
void push(int x) {
st.push(x);
if(mst.empty() || mst.top()>x)
mst.push(x);
else
mst.push(mst.top());
}
void pop() {
st.pop();
mst.pop();
}
int top() {
return st.top();
}
int getMin() {
return mst.top();
}
private:
stack<int> st;
stack<int> mst;
};