Skip to content

Commit cdf3526

Browse files
Update 150.py
1 parent 5c68168 commit cdf3526

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

001-500/150.py

+21
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,24 @@ def evalRPN(self, tokens: List[str]) -> int:
1818
stack.append(c)
1919

2020
return stack[-1]
21+
22+
23+
class Solution:
24+
def evalRPN(self, tokens: List[str]) -> int:
25+
s = []
26+
x = "+-*/"
27+
for token in tokens:
28+
if token not in x:
29+
s.append(int(token))
30+
else:
31+
a = s.pop()
32+
b = s.pop()
33+
if token=="+":
34+
s.append(a+b)
35+
elif token=="-":
36+
s.append(b-a)
37+
elif token=="*":
38+
s.append(a*b)
39+
else:
40+
s.append(int(b/a))
41+
return s[0]

0 commit comments

Comments
 (0)