Not sure if this was correct, but I got a successful submit on it ☺


#1

stackS;
dequeQ;
MinStack::MinStack() {
while(!S.empty())S.pop();
while(!Q.empty())Q.pop_front();
}

void MinStack::push(int x) {
if(x<Q.front())Q.push_front(x);
else Q.push_back(x);
S.push(x);
}

void MinStack::pop() {
if(S.empty())return;
if(S.top()==Q.front())Q.pop_front();
else Q.pop_back();
S.pop();
}

int MinStack::top() {
if(S.empty())return -1;
return S.top();
}

int MinStack::getMin() {
if(S.empty())return -1;
return Q.front();
}