Evaluate the value of an arithmetic expression in Reverse Polish Notation.
valid operators Are + , -, * , /. Each operand is an integer or another expression.
Some Examples:
["2", "1", "+", "3", "*")--((2 + 1) (3)-9 ["4", "", "5", "/", "+"], 4 + (13/5))
public class Solution {public int evalrpn (string[] tokens) {stack<integer> Stack = new stack<integer> (); for (i NT i = 0; i < tokens.length; i++) {if (Tokens[i].equals ("+")) {int a = Stack.pop (); int b = Stack.pop (); int res = B + a;stack.push (res);} else if (token S[i].equals ("-")) {int a = Stack.pop (); int b = Stack.pop (); int res = B-a;stack.push (res);} else if (Tokens[i].equals ("*" ) {int a = Stack.pop (); int b = Stack.pop (); int res = b * A;stack.push (res);} else if (tokens[i].equals ("/")) {int a = Stack.pop (); int b = Stack.pop (); int res = B/a;stack.push (res);} else {Stack.pus H (Integer.parseint (Tokens[i]));}} return Stack.peek ();}}
[Leetcode] Evaluate Reverse Polish Notation