본문 바로가기
python-algorithm

Leetcode 682. Baseball Game

by 무적김두칠 2021. 8. 30.

1
2
3
4
5
6
7
8
9
class Solution:
    def calPoints(self, ops: List[str]) -> int:
        tmp=[]
        for i in ops:
            if i=='C': tmp.pop()
            elif i=='D':tmp.append (tmp[-1]*2)
            elif i=="+":tmp.append(tmp[-1]+tmp[-2])
            else : tmp.append(int(i))
        return (sum(tmp))
cs
반응형

댓글