package leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * https://leetcode.com/problems/implement-stack-using-queues/
 */
public class Problem225 {
    static class MyStack {
        private Queue<Integer> list1 = new LinkedList<>();
        private Queue<Integer> list2 = new LinkedList<>();
            
        // Push element x onto stack.
        public void push(int x) {
            while (!list1.isEmpty()) {
                list2.add(list1.remove());
            }
            list1.add(x);
            while (!list2.isEmpty()) {
                list1.add(list2.remove());
            }
        }

        // Removes the element on top of the stack.
        public void pop() {
            list1.remove();
        }

        // Get the top element.
        public int top() {
            return list1.peek();
        }

        // Return whether the stack is empty.
        public boolean empty() {
            return list1.isEmpty();
        }
    }
    
    public static void main(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        
        stack.pop();
        stack.pop();
        stack.pop();
        
        stack.push(1);
        stack.push(2);
        
        System.out.println(stack.top());
    }
}

@@ -979,347 +979,6 @@
   %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

Update problem 225