解题代码
class CQueue { Stack<Integer> stackPush ; //压栈 Stack<Integer> stackPop ; //出栈 public CQueue() { // 初始化 stackPush = new Stack<>(); stackPop = new Stack<>(); } public void appendTail(int value) { stackPush.push(value); //入栈 } public int deleteHead() { if(stackPop.isEmpty() ) { while( !stackPush.isEmpty() ) { //将入栈信息全部压入弹出栈 stackPop.push(stackPush.pop() ); } } return stackPop.isEmpty() ? -1 : stackPop.pop(); }}/** * Your CQueue object will be instantiated and called as such: * CQueue obj = new CQueue(); * obj.appendTail(value); * int param_2 = obj.deleteHead(); */