-
Notifications
You must be signed in to change notification settings - Fork 0
/
150.py
37 lines (34 loc) · 815 Bytes
/
150.py
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
27
28
29
30
31
32
33
34
35
36
37
import math
class Solution(object):
def evalRPN(self, tokens):
"""
:type tokens: List[str]
:rtype: int
"""
def normal_cal(a,b,i):
if i=='+':
return a+b
elif i=='-':
return a-b
elif i=='*':
return a*b
elif i=='/':
return math.trunc(a/b)
stack=[]
for i in tokens:
if i not in ['+','-','*','/']:
stack.append(int(i))
else:
b=stack.pop(-1)
a=stack.pop(-1)
stack.append(normal_cal(a,b,i))
return stack[0]
#%%
tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
x=Solution
Solution.evalRPN(x,tokens)
#%%
a='+'
int(a)
#%%
a.isnumeric()