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