Skip to content

Latest commit

 

History

History
26 lines (24 loc) · 674 Bytes

682.-baseball-game.md

File metadata and controls

26 lines (24 loc) · 674 Bytes

682. Baseball Game

class Solution:
    def calPoints(self, ops: List[str]) -> int:
        ## "C" 
        ## 读题以后 天生stack
        ans = 0
        stack = []
        for p in ops:
            if p == "C":
                ans -= stack[-1]
                stack.pop()
            elif p == "D":
                ans += stack[-1]*2
                stack.append(stack[-1]*2)
            elif p == "+":
                ans += stack[-1] + stack[-2]
                stack.append(stack[-1] + stack[-2])
            else:
                stack.append(int(p))
                ans += int(p) 
        ## 这就是数据处理题....
        return ans