class MyStack {private Queue<Integer> queue=new LinkedList<>();/** Initialize your data structure here. */publicMyStack() {}/** Push element x onto stack. */publicvoidpush(int x) {queue.add(x);for(int i=1;i<queue.size();i++){queue.add(queue.poll());}}/** Removes the element on top of the stack and returns that element. */publicintpop() {return queue.poll();}/** Get the top element. */publicinttop() {return queue.peek();}/** Returns whether the stack is empty. */publicbooleanempty() {return queue.isEmpty();}}
class MyStack {private Queue<Integer> pollQ=new LinkedList<>(); private Queue<Integer> helpQ=new LinkedList<>();/** Initialize your data structure here. */publicMyStack() {}/** Push element x onto stack. */publicvoidpush(int x) {while(!pollQ.isEmpty()){helpQ.add(pollQ.poll());}pollQ.add(x);while(!helpQ.isEmpty()){pollQ.add(helpQ.poll());}}/** Removes the element on top of the stack and returns that element. */publicintpop() {return pollQ.poll();}/** Get the top element. */publicinttop() {return pollQ.peek();}/** Returns whether the stack is empty. */publicbooleanempty() {return pollQ.isEmpty();}}