题解 | #包含min函数的栈#
包含min函数的栈
https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49
#include <climits>
class Solution {
private:
stack<int> sta1;
stack<int> sta2;
public:
void push(int value) {
sta1.push(value);
if(sta2.empty()||sta2.top()>value){
sta2.push(value);
}else{
sta2.push(sta2.top());
}
}
void pop() {
sta1.pop();
sta2.pop();
}
int top() {
return sta1.top();
}
int min() {
return sta2.top();
}
};
