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

用两个栈实现队列

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
};

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

相关推荐

喜欢核冬天的哈基米很想上市:会爆NullPointerException的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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