题目链接
思路
两个栈模拟
代码
class CQueue {
Deque<Integer> inStack;
Deque<Integer> outStack;
public CQueue() {
inStack = new ArrayDeque<Integer>();
outStack = new ArrayDeque<Integer>();
}
public void appendTail(int value) {
inStack.push(value);
}
public int deleteHead() {
if(outStack.isEmpty()){
if(inStack.isEmpty()){
return -1;
}
in2out();
}
return outStack.pop();
}
private void in2out() {
while(!inStack.isEmpty()){
outStack.push(inStack.pop());
}
}
}
标签:Offer,09,outStack,public,isEmpty,inStack,LeetCode
From: https://www.cnblogs.com/shixuanliu/p/17195928.html