Wohoo! Python:)


#1

class MinStack:
# @param x, an integer
def init(self):
self.s = []
self.m = []
def push(self, x):
self.s.append(x)
if len(self.m)==0:
self.m.append(x)
elif self.m[-1]>=x:
self.m.append(x)
# @return nothing
def pop(self):
if len(self.s)!=0:
if self.s[-1]==self.m[-1]:
self.m.pop()
return self.s.pop()
return
# @return an integer
def top(self):
if len(self.s)!=0:
return self.s[-1]
return -1
# @return an integer
def getMin(self):
if len(self.m)!=0:
return self.m[-1]
return -1