You are viewing a single comment's thread. Return to all comments →
My Python Solution:
def getMax(operations): ans = [] stack = [] maxNum = None appNum = None for op in operations: opsl = op.split() if opsl[0] == '1': appNum = int(opsl[1]) stack.append(appNum) if maxNum and appNum > maxNum: maxNum = appNum elif opsl[0] == '2': if stack.pop() == maxNum: maxNum = None elif opsl[0] == '3': if not maxNum: maxNum = 0 for num in stack: if num > maxNum: maxNum = num ans.append(maxNum) return ans
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
My Python Solution: