https://leetcode-cn.com/problems/implement-queue-using-stacks/
class MyQueue {Stack<Integer> stack1;Stack<Integer> stack2;public MyQueue() {stack1 = new Stack<>();stack2 = new Stack<>();}public void push(int x) {// 1. S1 的全部元素进入 S2while (!stack1.isEmpty()){stack2.push(stack1.pop());}// 2. 将新元素压入 S1stack1.push(x);// 3. 再将 S2 中元素依次压入 S1while (!stack2.isEmpty()){stack1.push(stack2.pop());}}public int pop() {return stack1.pop();}public int peek() {return stack1.peek();}public boolean empty() {return stack1.isEmpty();}}
