Why i get TLE(time limit error)?


  • 0
    R
    class MinStack:
    
    	def __init__(self):
    	    self.stack = []
    
    	# @param x, an integer
    	# @return an integer
    	def push(self, x):
    		self.stack.append(x)
    
    	# @return nothing
    	def pop(self):
    		self.stack.pop()
    		return
    
    	# @return an integer
    	def top(self):
    	    return self.stack[-1]
    
    	# @return an integer
    	def getMin(self):
    		return min(self.stack)

  • 1
    M

    what the problem ask for is to get minimum item in constant time. your getMin() function definitely takes O(n) time.


  • 0
    A

    What was the mistake?


Log in to reply
 

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