Easy Python | High Speed
Easy Python | High Speed\n\nEasy Python solution using an array A to store the elements placed in the stack, and an additional array M tracking the minimum elem
**Easy Python | High Speed**\n\nEasy Python solution using an array ```A``` to store the elements placed in the stack, and an additional array ```M``` tracking the minimum element seen so far. It can be proven that this approach always works, although it uses ```O(N)``` extra space. (It doesn\'t change the overall space complexity though).\n\nI hope the explanation was helpful.\nCheers,\n\n```\nclass MinStack:\n    def __init__(self):\n        self.A = []\n        self.M = []\n    def push(self, x):\n        self.A.append(x)\n        self.M.append( x if not self.M else min(x, self.M[-1]) )\n    def pop(self):\n        self.A.pop()\n        self.M.pop()\n    def top(self):\n        return self.A[-1]\n    def getMin(self):\n        return self.M[-1]\n```
['Python', 'Python3']