https://leetcode-cn.com/problems/implement-queue-using-stacks/
/*** Your MyQueue object will be instantiated and called as such:* var obj = new MyQueue()* obj.push(x)* var param_2 = obj.pop()* var param_3 = obj.peek()* var param_4 = obj.empty()*/class MyQueue {private stack1: number[] = []private stack2: number[] = []constructor() {}push(x: number): void {this.stack1.push(x)}// 从队列的开头移除并返回元素pop(): number|undefined {let res;// 将 stack 移动到 stack2while (this.stack1.length){const n = this.stack1.pop()if (n!== undefined)this.stack2.push(n)}res = this.stack2.pop()while (this.stack2.length){const n = this.stack2.pop()if (n!== undefined)this.stack1.push(n)}return res || undefined}peek(): number | undefined {if (this.stack1.length > 0) {return this.stack1[0]}}empty(): boolean {return this.stack1.length === 0}}
