class MinStack(object): def __init__(self): """ initialize your data structure here. """ self._elem=[] def push(self, x): """ :type x: int :rtype: None """ self._elem.append(x) def pop(self): """ :rtype: None """ return self._elem.pop() def top(self): """ :rtype: int """ return self._elem[-1] def getMin(self): """ :rtype: int """ return min(self._elem) # Your MinStack object will be instantiated and called as such: # obj = MinStack() # obj.push(x) # obj.pop() # param_3 = obj.top() # param_4 = obj.getMin()
When execution: 660 ms, beat the 24.93% of all users to submit in python
Memory consumption: 15.5 MB, defeated 19.17% of all users to submit in python
——2019.11.2