Leetcode
682. Baseball Game
YGSEO
2020. 7. 19. 02:35
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