private Stack<Integer> stack = new Stack<>(); private Stack<Integer> minStack = new Stack<>(); public void push(int node) { stack.push(node); if (minStack.isEmpty()){ minStack.push(node); }else { if (minStack.peek() >= node){ minStack.push(node); } } } public void pop() { if (stack.isEmpty()){ return; } int num = stack.pop(); if (minStack.peek() == num){ minStack.pop(); } } public int top() { return stack.peek(); } public int min() { return minStack.peek(); }