思路
- Make push() inefficient
- Make pop() and peek() inefficient
- Rotate the queue itself in push()
Bug
- Method 3: rotate the queue.
- Rotate time is
q.size() - 1
rather thanq.size()
times. Make the last element to the head!
- Rotate time is
for (int i = 1; i < q1.size(); i++) {
q1.add(q1.poll());
}