class MinStack {
private:
stack<int> s1;
stack<int> s2;
public:
void push(int x) {
s1.push(x);
if (s2.empty() || x <= s2.top() ) s2.push(x); //判断是否为空要在前,且等于号不能少
}
void pop() {
if (s1.top() == getMin()) s2.pop(); //class内部调用
s1.pop();
}
int top() {
return s1.top();
}
int getMin() {
return s2.top();
}
};