Submission Detail

21 / 21 test cases passed.
Status:

Accepted

Runtime: 55 ms
Memory Usage: 15.7 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

30
40
50
60
70
80
90
100
110
1
2
3
4
5
6
7
8
python
You are here!
Your runtime beats 42.98 % of python submissions.
Runtime (ms)
Distribution (%)

30
40
50
60
70
80
90
100
110
2.5
5.0
7.5
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

14700
14800
14900
15000
15100
15200
15300
15400
15500
15600
5
10
15
20
25
30
python
Memory (KB)
Distribution (%)

14700
14800
14900
15000
15100
15200
15300
15400
15500
15600
10
20
30
Zoom area by dragging across this chart

Invite friends to challenge Evaluate Reverse Polish Notation


Submitted Code: 0 minutes ago

Language: python

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
class Solution(object):
def evalRPN(self, tokens):
"""
:type tokens: List[str]
:rtype: int
"""
stack = []
res = 0
for i in range(0,len(tokens)):
if (tokens[i] != "+" and
tokens[i] != "-" and
tokens[i] != "*" and
tokens[i] != "/"):
stack.append(int(tokens[i]))
elif (tokens[i] == "+"):
res = stack.pop(-2) + stack.pop()
stack.append(res)
elif (tokens[i] == "-"):
res = stack.pop(-2) - stack.pop()
stack.append(res)
elif (tokens[i] == "*"):
res = stack.pop(-2) * stack.pop()
stack.append(res)
elif (tokens[i] == "/"):
n1 = float(stack.pop(-2))
n2 = float(stack.pop())
res = int(n1 / n2)
stack.append(res)
return stack.pop()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX