Simple Java solution using two build-in stacks
Here is my simple code for minStack, using two build in Java stack to store the stack and min values separately.\n\n    class MinStack {\n        // stack: stor
Here is my simple code for minStack, using two build in Java stack to store the stack and min values separately.\n\n    class MinStack {\n        // stack: store the stack numbers\n        private Stack<Integer> stack = new Stack<Integer>();\n        // minStack: store the current min values\n        private Stack<Integer> minStack = new Stack<Integer>();\n        \n        public void push(int x) {\n            // store current min value into minStack\n            if (minStack.isEmpty() || x <= minStack.peek())\n                minStack.push(x);\n            stack.push(x);\n        }\n    \n        public void pop() {\n            // use equals to compare the value of two object, if equal, pop both of them\n            if (stack.peek().equals(minStack.peek()))\n                minStack.pop();\n            stack.pop();\n        }\n    \n        public int top() {\n            return stack.peek();\n        }\n    \n        public int getMin() {\n            return minStack.peek();\n        }\n    }
[]