forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
25 lines (20 loc) · 704 Bytes
/
base.py
File metadata and controls
25 lines (20 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution(object):
def calPoints(self, ops):
"""
:type ops: List[str]
:rtype: int
"""
score = []
for i in range(len(ops)):
if ops[i].isdigit():
score.append(int(ops[i]))
elif "-" in ops[i] and ops[i][1].isdigit():
score.append(int(ops[i]))
elif ops[i] == "+":
score.append(int(score[-1])+int(score[-2]))
elif ops[i] == "C":
score.pop()
elif ops[i] == "D":
score.append(2*int(score[-1]))
#print score
return sum(score)