c++
class MinStack {
public:
/** initialize your data structure here. */
int s1[10005];
int s2[10005];
int top1;
int top2;
MinStack() {
top1=-1;
top2=-1;
}
void push(int x) {
s1[++top1] =x;
if(top2==-1)
{
s2[++top2]=x;
}
else
{
if(x<=s2[top2])
{
s2[++top2]=x;
}
}
}
void pop() {
if(s1[top1]==s2[top2])
top2--;
top1--;
}
int top() {
return s1[top1];
}
int getMin() {
return s2[top2];
}
};
/**
* 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();
*/