17/18 test cases passed ,getting memory limit exceeded error


  • 0
    N

    class MinStack(object):
    def init(self):
    """
    initialize your data structure here.
    """
    self.items = []

    def push(self, x):
        """
        :type x: int
        :rtype: void
        """
        self.items.append(x)
        
    
    
    def pop(self):
        """
        :rtype: void
        """
        return self.items.pop()
    def top(self):
        """
        :rtype: int
        """
        return self.items[len(self.items)-1]
    
    def getMin(self):
        """
        :rtype: int
        """
        min_num=self.items[0]
        for i in range(1,len(self.items)):
            if self.items[i]<min_num:
                min_num=self.items[i]
        return min_num
    

    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()


Log in to reply
 

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