题解 | #用两个栈实现队列#
用两个栈实现队列
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
};
#我的实习求职记录#