class MinStack {
public:
/** initialize your data structure here. */
stack<int> minstack;
stack<int> outStack;
MinStack() {
minstack.push(INT_MAX);
}
void push(int x) {
outStack.push(x);
minstack.push(min(minstack.top(),x));
}
void pop() {
outStack.pop();
minstack.pop();
}
int top() {
return outStack.top();
}
int getMin() {
return minstack.top();
}
};
力扣面试题03.02:栈的最小值
最新推荐文章于 2024-07-11 23:32:17 发布