class MinStack {
public:
stack
<int> x_stack
;
stack
<int> min_stack
;
MinStack() {
min_stack
.push(INT_MAX
);
}
void push(int x
) {
x_stack
.push(x
);
min_stack
.push(min(min_stack
.top(), x
));
}
void pop() {
x_stack
.pop();
min_stack
.pop();
}
int top() {
return x_stack
.top();
}
int getMin() {
return min_stack
.top();
}
};
转载请注明原文地址: https://lol.8miu.com/read-29926.html