Skip to content

682 Baseball Game

682. Baseball Game

题目: https://leetcode.com/problems/Baseball-Game/

难度:

Easy

思路

points用来存放每一次的分数,最后求和。

class Solution(object):
    def calPoints(self, ops):
        """
        :type ops: List[str]
        :rtype: int
        """
        points = []
        for i in ops:
            if i == 'C':
                points.pop()
            elif i == 'D':
                points.append(2 * points[-1])
            elif i == '+':
                points.append(points[-1] + points[-2])
            else:
                points.append(int(i))
        return sum(points)


回到顶部