牛客网基于min函数的栈题解部分
发布时间
阅读量:
阅读量
class Solution {
private:
stack<int> minst;
stack<int> st;
public:
void push(int value) {
st.push(value);
if(minst.empty()){
minst.push(value);
}
else if(minst.top()>=value){
minst.push(value);
}
}
void pop() {
if(minst.top() == st.top()){
minst.pop();
}
st.pop();
}
int top() {
return st.top();
}
int min() {
return minst.top();
}
};
全部评论 (0)
还没有任何评论哟~
