3
private final Deque<Integer> stack = new ArrayDeque<>();4
private final Deque<Integer> temp = new ArrayDeque<>();6
/** Initialize your data structure here. */9
/** Pushes element x to the back of the queue. */10
public void push(int x) {15
* @return the element at the front of the queue and remove it.18
while (stack.size() > 1) temp.push(stack.pop());20
var val = stack.pop();21
while (!temp.isEmpty()) stack.push(temp.pop());27
* @return the element at the front of the queue.30
while (stack.size() > 1) temp.push(stack.pop());32
var val = stack.peek();33
while (!temp.isEmpty()) stack.push(temp.pop());39
* @return true if the queue is empty, false otherwise.41
public boolean empty() {42
return stack.isEmpty();