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

