

解题思路:
使用一个辅助栈,两个栈可以模拟队列
pop()时使用stackOut,stackOut为空时,需要把所有的stackIn中的元素放入
class MyQueue {Stack<Integer> stackIn;Stack<Integer> stackOut;public MyQueue() {stackIn = new Stack<>();stackOut = new Stack<>();}public void push(int x) {stackIn.push(x);}public int pop() {if (stackOut.isEmpty()) {while (!stackIn.isEmpty()) stackOut.push(stackIn.pop());}return stackOut.pop();}public int peek() {int tmp = this.pop();stackOut.push(tmp);return tmp;}public boolean empty() {if (stackIn.isEmpty() && stackOut.isEmpty()) return true;return false;}
}
