simple python, beat 94.62%


  • 0
    F
        def calPoints(self, ops):
            scores = []
            for op in ops:
                if op == 'C':
                    scores.pop()
                elif op == 'D':
                    scores.append(2 * scores[-1])
                elif op == '+':
                    scores.append(sum(scores[-2:]))
                else:
                    scores.append(int(op))
            return sum(scores)

Log in to reply
 

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