Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cdf3526

Browse filesBrowse files
Update 150.py
1 parent 5c68168 commit cdf3526
Copy full SHA for cdf3526

File tree

1 file changed

+21
-0
lines changed
Filter options

1 file changed

+21
-0
lines changed

‎001-500/150.py

Copy file name to clipboardExpand all lines: 001-500/150.py
+21Lines changed: 21 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.