Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitcdf3526

Browse files
Update 150.py
1 parent5c68168 commitcdf3526

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎001-500/150.py

Lines 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
returnstack[-1]
21+
22+
23+
classSolution:
24+
defevalRPN(self,tokens:List[str])->int:
25+
s= []
26+
x="+-*/"
27+
fortokenintokens:
28+
iftokennotinx:
29+
s.append(int(token))
30+
else:
31+
a=s.pop()
32+
b=s.pop()
33+
iftoken=="+":
34+
s.append(a+b)
35+
eliftoken=="-":
36+
s.append(b-a)
37+
eliftoken=="*":
38+
s.append(a*b)
39+
else:
40+
s.append(int(b/a))
41+
returns[0]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp