@@ -0,0 +1,1112 @@
+/***%0A * Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.%0A *%0A * push(x) -- Push element x onto stack.%0A * pop() -- Removes the element on top of the stack.%0A * top() -- Get the top element.%0A * getMin() -- Retrieve the minimum element in the stack.%0A */%0Aimport java.util.Stack;%0A%0Apublic class MinStack %7B%0A%0A    long min;%0A    Stack%3CLong%3E stack;%0A%0A    public MinStack()%7B%0A        stack=new Stack%3C%3E();%0A    %7D%0A    %0A    public void push(int x) %7B%0A    %0A        if (stack.isEmpty())%7B%0A            stack.push(0L);%0A            min=x;%0A        %7Delse%7B%0A            stack.push(x-min);//Could be negative if min value needs to change%0A            if (x%3Cmin) min=x;%0A        %7D%0A    %7D%0A  %0A    public void pop() %7B%0A        if (stack.isEmpty()) return;%0A        long pop=stack.pop();%0A        if (pop%3C0)  min=min-pop;//If negative, increase the min value%0A    %7D%0A    %0A    public int top() %7B%0A        long top=stack.peek();%0A        if (top%3E0)%7B%0A            return (int)(top+min);%0A        %7Delse%7B%0A            return (int)(min);%0A        %7D%0A    %7D%0A    %0A    public int getMin() %7B%0A        return (int)min;%0A    %7D%0A%0A%7D%0A

add MinStack.java