Skip to content

Commit a8de153

Browse files
authored
150
1 parent d18421c commit a8de153

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Runtime 5ms
2+
// Beats 97.05%
3+
// Memory 44.35MB
4+
// Beats 62.56%
5+
class Solution {
6+
public int evalRPN(String[] tokens) {
7+
Stack<Integer>st=new Stack<>();
8+
int y;
9+
for(String str: tokens){
10+
if(str.equals("+"))
11+
st.push(st.pop()+st.pop());
12+
else if(str.equals("-"))
13+
st.push(-st.pop()+st.pop());
14+
else if(str.equals("*"))
15+
st.push(st.pop()*st.pop());
16+
else if(str.equals("/")){
17+
y=st.pop();
18+
st.push(st.pop()/y);
19+
}
20+
else
21+
st.push(Integer.parseInt(str));
22+
}
23+
return st.peek();
24+
25+
}
26+
}

0 commit comments

Comments
 (0)