@@ -0,0 +1,1549 @@
+import java.util.ArrayList;%0D%0Aimport java.util.Collections;%0D%0Aimport java.util.List;%0D%0A%0D%0A/**%0D%0A * %0D%0A */%0D%0A%0D%0A/**%0D%0A * @author qienl%0D%0A *%0D%0A */%0D%0Apublic class MinStack %7B%0D%0A%0D%0A%09private int size;%0D%0A%0D%0A%09private Node head = null;%0D%0A%0D%0A%09private Integer min = null;%0D%0A%0D%0A%09private class Node %7B%0D%0A%09%09int value;%0D%0A%09%09Node next;%0D%0A%0D%0A%09%09public Node(int value, Node next) %7B%0D%0A%09%09%09this.value = value;%0D%0A%09%09%09this.next = next;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public MinStack() %7B%0D%0A%09%7D%0D%0A%0D%0A%09public void push(int x) %7B%0D%0A%09%09this.size++;%0D%0A%09%09this.head = new Node(x, this.head);%0D%0A%09%09if (this.min == null %7C%7C x %3C this.min) %7B%0D%0A%09%09%09this.min = x;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public void pop() %7B%0D%0A%09%09if (head != null) %7B%0D%0A%09%09%09size--;%0D%0A%09%09%09int top = head.value;%0D%0A%09%09%09head = head.next;%0D%0A%09%09%09if (head == null) %7B%0D%0A%09%09%09%09this.min = null;%0D%0A%09%09%09%7D else if (min != null && top == min) %7B%0D%0A%09%09%09%09List%3CInteger%3E tempList = new ArrayList%3C%3E(this.size);%0D%0A%09%09%09%09for (Node temp = head; temp != null; temp = temp.next) %7B%0D%0A%09%09%09%09%09if (min == temp.value) %7B%0D%0A%09%09%09%09%09%09return;%0D%0A%09%09%09%09%09%7D%0D%0A%09%09%09%09%09tempList.add(temp.value);%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%09Collections.sort(tempList);%0D%0A%09%09%09%09this.min = tempList.get(0);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public int top() %7B%0D%0A%09%09if (head != null) %7B%0D%0A%09%09%09return head.value;%0D%0A%09%09%7D%0D%0A%09%09throw new RuntimeException(%22Empty stack%22);%0D%0A%09%7D%0D%0A%0D%0A%09public int getMin() %7B%0D%0A%09%09if (head != null && min != null) %7B%0D%0A%09%09%09return this.min;%0D%0A%09%09%7D%0D%0A%09%09throw new RuntimeException(%22Empty stack%22);%0D%0A%09%7D%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09MinStack obj = new MinStack();%0D%0A%09%09obj.push(-2);%0D%0A%09%09obj.push(0);%0D%0A%09%09obj.push(-3);%0D%0A%09%09obj.getMin();%0D%0A%09%09obj.pop();%0D%0A%09%09obj.top();%0D%0A%09%09System.out.println(obj.getMin());%0D%0A%09%7D%0D%0A%7D%0D%0A

Add MinStack.java