본문 바로가기
Leetcode

682. Baseball Game

by YGSEO 2020. 7. 19.
728x90
class Solution:
    def calPoints(self, ops: List[str]) -> int:
        a=[]
        for i in ops:
            if i=='C':
                a.pop()
            elif i=='D':
                a.append(a[-1]*2)
            elif i=='+':
                a.append(a[-1]+a[-2])
            else:
                a.append(int(i))
        return sum(a)

int 조건을 처음으로 하기보다는 맨 마지막으로 넣어서

728x90

'Leetcode' 카테고리의 다른 글

20. Valid Parentheses  (0) 2020.07.21
844. Backspace String Compare  (0) 2020.07.21
496. Next Greater Element I  (0) 2020.07.06
1047. Remove All Adjacent Duplicates In String  (0) 2020.07.05
1441. Build an Array With Stack Operations  (0) 2020.07.01

댓글