记得,要写成x <= MIN!!!!
class MinStack {
public:
/** initialize your data structure here. */
MinStack() {
}
void push(int x) {
if (x <= min)
{
S.push(min);
min = x;
}
S.push(x);
}
void pop() {
if (S.top() == min)
{
S.pop();
min = S.top();
S.pop();
}
else S.pop();
}
int top() {
return S.top();
}
int getMin() {
return min;
}
private:
stack<int> S;
int min = INT_MAX;
};