@@ -0,0 +1,910 @@
+// Idea is keeping two stacks: one of values and another one for min value at each level, and%0A// push into both stacks and pop from both stacks.%0Aclass MinStack %7B%0A  private LinkedList%3CInteger%3E stack;%0A  private LinkedList%3CInteger%3E min;%0A%0A  /** initialize your data structure here. */%0A  public MinStack() %7B%0A    this.stack = new LinkedList%3CInteger%3E();%0A    this.min = new LinkedList%3CInteger%3E();%0A  %7D%0A%0A  public void push(int x) %7B%0A    stack.push(x);%0A    if (min.isEmpty()) %7B%0A      min.push(x);%0A    %7D else %7B%0A      min.push(Math.min(min.peek(), x));%0A    %7D%0A  %7D%0A%0A  public void pop() %7B%0A    stack.pop();%0A    min.pop();%0A  %7D%0A%0A  public int top() %7B%0A    return stack.peek();%0A  %7D%0A%0A  public int getMin() %7B%0A    return min.peek();%0A  %7D%0A%7D%0A%0A/**%0A * Your MinStack object will be instantiated and called as such:%0A * MinStack obj = new MinStack();%0A * obj.push(x);%0A * obj.pop();%0A * int param_3 = obj.top();%0A * int param_4 = obj.getMin();%0A */%0A

add solution