用两个栈实现一个队列
#code
class Queue {
#stack1 = []
#stack2 = []
add(value){
this.#stack1.push(value)
return this.#stack1.length
}
delete(){
while(this.#stack1.length){
this.#stack2.push(this.#stack1.pop())
}
const popValue = this.#stack2.pop()
while(this.#stack2.length){
this.#stack1.push(this.#stack2.pop())
}
return popValue
}
get length(){
return this.#stack1.length
}
}
以自己现在的努力程度,还没有资格和别人拼天赋

浙公网安备 33010602011771号