题解 | #用两个栈实现队列#

用两个栈实现队列

https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6

var stack1 = []
var stack2 = []

function push(node)
{
    stack1.push(node)
}
function pop()
{   
    if(!stack2.length){
        if(stack1.length == 0)
          return null;
        while(stack1.length){
            stack2.push(stack1.pop())
        }
    }
    return stack2.pop()
}
module.exports = {
    push : push,
    pop : pop
};

全部评论

相关推荐

运营3年修炼中接简历辅导:你的科研项目经历里,只写了你的动作,没有写你的思考和成果,不要只写使用什么进行了什么,这等于罗列你的任务,简历是为了突出你的优秀,你在什么样的任务背景下,克服了什么样的困难,针对性地做了哪些事情,最后达成了什么成果(用数据体现你的成果和效率)
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务