题解 | #包含min函数的栈#

包含min函数的栈

https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49

var stack = [];
var minstack =[];
function push(node)
{
    if(minstack.length === 0){
        minstack.push(node);
    }else{
        minstack.push(Math.min(minstack[minstack.length-1],node));
    }
    stack.push(node);
}
function pop()
{
    // write code here
    minstack.pop();
    stack.pop();
}
function top()
{
    // write code here
    return stack[stack.length-1];
}
function min()
{
    // write code here
    return minstack[minstack.length-1];
}
module.exports = {
    push : push,
    pop : pop,
    top : top,
    min : min
};

全部评论

相关推荐

07-02 13:52
门头沟学院 Java
点赞 评论 收藏
分享
06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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