class MinStack { Deque<Integer> stack; Deque<Integer> min_stack; /** initialize your data structure here. */ public MinStack() { stack = new LinkedList<>(); min_stack = new LinkedList<>(); } public void push(int x) { stack.push(x); if(min_stack.size()!=0) min_stack.push(Math.min(min_stack.peek(),x)); else{ min_stack.push(x); } } public void pop() { stack.pop(); min_stack.pop(); } public int top() { return stack.peek(); } public int getMin() { return min_stack.peek(); } }