We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c68168 commit cdf3526Copy full SHA for cdf3526
001-500/150.py
@@ -18,3 +18,24 @@ def evalRPN(self, tokens: List[str]) -> int:
18
stack.append(c)
19
20
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
40
+ s.append(int(b/a))
41
+ return s[0]
0 commit comments