Simple python solution. Beat 0.64% of all submissions!


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

  • 0

    This is not cool, man.


Log in to reply
 

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