Skip to content

Latest commit

 

History

History
25 lines (23 loc) · 546 Bytes

682.md

File metadata and controls

25 lines (23 loc) · 546 Bytes
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

栈 算法