@@ -0,0 +1,1325 @@
+package leetcode;%0A%0Aimport java.util.LinkedList;%0Aimport java.util.Queue;%0A%0A/**%0A * https://leetcode.com/problems/implement-stack-using-queues/%0A */%0Apublic class Problem225 %7B%0A    static class MyStack %7B%0A        private Queue%3CInteger%3E list1 = new LinkedList%3C%3E();%0A        private Queue%3CInteger%3E list2 = new LinkedList%3C%3E();%0A            %0A        // Push element x onto stack.%0A        public void push(int x) %7B%0A            while (!list1.isEmpty()) %7B%0A                list2.add(list1.remove());%0A            %7D%0A            list1.add(x);%0A            while (!list2.isEmpty()) %7B%0A                list1.add(list2.remove());%0A            %7D%0A        %7D%0A%0A        // Removes the element on top of the stack.%0A        public void pop() %7B%0A            list1.remove();%0A        %7D%0A%0A        // Get the top element.%0A        public int top() %7B%0A            return list1.peek();%0A        %7D%0A%0A        // Return whether the stack is empty.%0A        public boolean empty() %7B%0A            return list1.isEmpty();%0A        %7D%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        MyStack stack = new MyStack();%0A        stack.push(1);%0A        stack.push(2);%0A        stack.push(3);%0A        %0A        stack.pop();%0A        stack.pop();%0A        stack.pop();%0A        %0A        stack.push(1);%0A        stack.push(2);%0A        %0A        System.out.println(stack.top());%0A    %7D%0A%7D%0A

Solve problem 225