Why TLE? I think it's ok..Did I miss something?


  • 0
    Z

    class MinStack:

    @param x, an integer

    def init(self):
    # the stack it self
    self.A = []
    self.minS=[]

    @return an integer

    def push(self, x):
    n=len(self.A)
    if n==0:
    self.minS.append(x)
    else:
    lastmin=self.minS[-1]
    if x<=lastmin:
    self.minS.append(x)
    self.A.append(x)

    @return nothing

    def pop(self):
    if len(self.A)>0 and self.A.pop()==self.minS[-1]:
    self.minS.pop()

    @return an integer

    def top(self):
    return self.A[-1]

    @return an integer

    def getMin(self):
    return self.minS[-1]


Log in to reply
 

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