Baseball Game LeetCode solution in Python

1
class Solution:
2
def calPoints(self, ops: List[str]) -> int:
3
temp = []
4
for i in ops:
5
if i != "C" and i != "D" and i != "+":
6
temp.append(int(i))
7
elif i == "C":
8
temp.remove(temp[len(temp) - 1])
9
elif i == "D":
10
temp.append(2 * temp[len(temp) - 1])
11
elif i == "+":
12
temp.append(temp[len(temp) - 1] + temp[len(temp) - 2])
13

14
return sum(temp)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0