-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path150.py
More file actions
26 lines (25 loc) · 797 Bytes
/
150.py
File metadata and controls
26 lines (25 loc) · 797 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
26
class Solution(object):
def evalRPN(self, tokens):
"""
:type tokens: List[str]
:rtype: int
"""
stack=[]
for i in tokens:
if i !='+' and i !='-' and i !='*' and i !='/' :
stack.append(i)
else:
num2=int(stack.pop())
num1=int(stack.pop())
if i=='+':
res=num1+num2
elif i=='-':
res=num1-num2
elif i=='*':
res=num1*num2
elif i=='/':
res=int(float(num1)/float(num2))
stack.append(res)
return int(stack[0])
token=["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
print(Solution().evalRPN(tokens=token))