
class MyStack {
Queue<Integer> queue = new LinkedList<>();
Queue<Integer> helper = new LinkedList<>();
public MyStack() {
}
public void push(int x) {
queue.offer(x);
}
public int pop() {
int tmp = 0;
while (queue.size() > 1) {
tmp = queue.poll();
helper.offer(tmp);
}
tmp = queue.poll();
while(!helper.isEmpty()) {
queue.offer(helper.poll());
}
return tmp;
}
public int top() {
int tmp = 0;
while (!queue.isEmpty()) {
tmp = queue.poll();
helper.offer(tmp);
}
while(!helper.isEmpty()) {
queue.offer(helper.poll());
}
return tmp;
}
public boolean empty() {
return queue.isEmpty();
}
}