Leetcode 682.棒球比赛

PYTHON实现

class Solution:
    def calPoints(self, ops: List[str]) -> int:
        Stack=[]
        for op in ops:
            if op=="+":
                Stack.append(Stack[-1]+Stack[-2])
            elif op=="D":
                Stack.append(2*Stack[-1])
            elif op=="C":
                Stack.pop()
            else:
                Stack.append(int(op))
        return sum(Stack)
        

执行用时56ms
消耗内存13.8MB
2019.8.23

发布了22 篇原创文章 · 获赞 0 · 访问量 274

猜你喜欢

转载自blog.csdn.net/chang_sheng1/article/details/100047174