155. 最小栈(c++)
作者:互联网
class MinStack {
stack<int>stack1;
stack<int>min_stack;
public:
MinStack() {
min_stack.push(INT_MAX);
}
void push(int val) {
stack1.push(val);
min_stack.push(min(min_stack.top(),val));
}
void pop() {
stack1.pop();
min_stack.pop();
}
int top() {
return stack1.top();
}
int getMin() {
return min_stack.top();
}
};
/**
* Your MinStack object will be instantiated and called as such:
* MinStack* obj = new MinStack();
* obj->push(val);
* obj->pop();
* int param_3 = obj->top();
* int param_4 = obj->getMin();
*/
标签:155,min,int,top,最小,c++,obj,MinStack,stack 来源: https://blog.csdn.net/qq_36421001/article/details/122778698