题解 | #包含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();
    }
};

全部评论

相关推荐

07-31 14:40
门头沟学院 Java
代码主理人:触发重传机制了,可能是服务器负载太高了,ACK丢包了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
09-18 15:39
门头沟学院 Java
小肥罗:感谢信+10086
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务