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

用两个栈实现队列

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

var stack1 = [];
var stack2 = [];
function push(node)
{
    // write code here
    stack1.push(node)
}
var res = [];
function pop()
{
    // write code here
    if(stack1.length == 0){
        return null;
    }
    while(stack1.length != 1){
        stack2.push(stack1.pop());
    }
    res.push(stack1.pop());
    while(stack2.length != 0){
        stack1.push(stack2.pop());
    }
    return res.pop();
}
module.exports = {
    push : push,
    pop : pop
};

#我的实习求职记录#
全部评论

相关推荐

昨天 23:48
蚌埠坦克学院
csgq:可能没hc了 昨天一面完秒挂
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务