https://leetcode-cn.com/problems/implement-stack-using-queues/
class MyStack {Queue<Integer> queue;public MyStack() {queue = new LinkedList<>();}public void push(int x) {// 1. 首先记录当前队列长度int size = queue.size();// 2. 把 x 入队queue.offer(x);// 3. Q 中原先所有的元素先出队,然后再入队for (int i = 0; i < size; i++) {queue.offer(queue.poll());}}public int pop() {return queue.poll();}public int top() {return queue.peek();}public boolean empty() {return queue.isEmpty();}}/*** Your MyStack object will be instantiated and called as such:* MyStack obj = new MyStack();* obj.push(x);* int param_2 = obj.pop();* int param_3 = obj.top();* boolean param_4 = obj.empty();*/
