A simple Python solution


  • 0
    D
    class MinStack(object):
    
        def __init__(self):
            """
            initialize your data structure here.
            """
            self._stack = []
            
    
        def push(self, x):
            """
            :type x: int
            :rtype: void
            """
            self._stack.append(x)
            
    
        def pop(self):
            """
            :rtype: void
            """
            self._stack.pop()
            
    
        def top(self):
            """
            :rtype: int
            """
            return self._stack[-1]
    
        def getMin(self):
            """
            :rtype: int
            """
            return min(self._stack)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.