class MinStack {
public:
stack
<int> s1
;
stack
<int> s2
;
MinStack() {
}
void push(int x
) {
s1
.push(x
);
if(s2
.empty()) s2
.push(x
);
else if(s2
.top()<x
) s2
.push(s2
.top());
else s2
.push(x
);
}
void pop() {
s1
.pop();
s2
.pop();
}
int top() {
return s1
.top();
}
int min() {
return s2
.top();
}
};
转载请注明原文地址:https://blackberry.8miu.com/read-33834.html