class Solution(object):
def calPoints(self, ops):
"""
:type ops: List[str]
:rtype: int
"""
result = []
for i in range(len(ops)):
if ops[i]=='+':
data = result[-1]+result[-2]
result.append(data)
elif ops[i] == 'D':
data = result[-1]*2
result.append(data)
elif ops[i] == 'C':
# 默认移除最后一个元素
data = result.pop()
else:
result.append(int(ops[i]))
return sum(result)
每日一道Leetcode - 682. 棒球比赛
最新推荐文章于 2024-09-03 17:37:40 发布