/**
* 自己的代码
* 执行用时:40 ms, 在所有 Java 提交中击败了99.71%
* 内存消耗:47.3 MB, 在所有 Java 提交中击败了14.36%
*/
class CQueue {
LinkedList<Integer> sPush, sPop;
public CQueue() {
sPush = new LinkedList();
sPop = new LinkedList();
}
public void appendTail(int value) {
sPush.push(value);
}
public int deleteHead() {
if (!sPop.isEmpty()) {
return sPop.pop();
} else {
while (!sPush.isEmpty()) {
sPop.push(sPush.pop());
}
return sPop.isEmpty() ? -1 : sPop.pop();
}
}
}
08-20
08-20
08-20
08-20