题目链接:
https://leetcode.cn/problems/bao-han-minhan-shu-de-zhan-lcof/description/?favorite=xb9nqhhg
代码 :
class MinStack {
public:
stack<int>s;
stack<int>f;
/** initialize your data structure here. */
MinStack() {
f.push(INT_MAX);
}
void push(int x) {
s.push(x);
f.push( ::min(f.top(),x));
}
void pop() {
f.pop();
s.pop();
}
int top() {
return s.top();
}
int min() {
return f.top();
}
};
/**
* Your MinStack object will be instantiated and called as such:
* MinStack* obj = new MinStack();
* obj->push(x);
* obj->pop();
* int param_3 = obj->top();
* int param_4 = obj->min();
*/