• + 1 comment

    sol by python 3:

    def getMax(operations):
        answer=[]
        arr=[]
        max_value=[-math.inf]
        for oper in operations:
            now_operation=oper.split()
            if now_operation[0]=='1':
                new_value=int(now_operation[1])
                arr.append(new_value)
                max_value.append(max(max_value[-1], new_value))
            elif now_operation[0]=='2':
                arr.pop(-1)
                max_value.pop(-1)
            else:
                answer.append(max_value[-1])
        return answer