• + 0 comments

    Python

    Solution

    def getMax(operations):

    stack = list()
    sol = list()
    max_number = [0]
    
    for i in operations:
        if i[0]=='1':
            number = int(i[2:])
            stack.append(number)
            if number >= max_number[-1]:
                max_number.append(number)
    
        elif i[0]=='2' and stack:
            poppednumber = stack.pop()
            if poppednumber==max_number[-1]:
                max_number.pop()
    
        elif i[0]=='3':
            sol.append(max_number[-1])
    
    return sol