Wednesday, November 22, 2017

682. Baseball Game

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

No comments:

Post a Comment