Evaluate the value of an arithmetic expression in Reverse Polish Notation.

Valid operators are +, -, *, and /. Each operand may be an integer or another expression.

Note that division between two integers should truncate toward zero.

It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation.

&nbsp;
Example 1:

Input: tokens = ["2","1","+","3","*"]
Output: 9
Explanation: ((2 + 1) * 3) = 9


Example 2:

Input: tokens = ["4","13","5","/","+"]
Output: 6
Explanation: (4 + (13 / 5)) = 6


Example 3:

Input: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
Output: 22
Explanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
= ((10 * (6 / (12 * -11))) + 17) + 5
= ((10 * (6 / -132)) + 17) + 5
= ((10 * 0) + 17) + 5
= (0 + 17) + 5
= 17 + 5
= 22


&nbsp;
Constraints:


	1 &lt;= tokens.length &lt;= 104
	tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].


class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        stack = []      
        for i in tokens:
            if i == "+":
                stack[-1] = stack[-2] + stack.pop()
            elif i == "-":
                stack[-1] = stack[-2] - stack.pop()
            elif i == "*":
                stack[-1] = stack[-2] * stack.pop()
            elif i == "/":
                stack[-1] = int(stack[-2] / stack.pop())
            else:
                stack.append(int(i))
                
        return stack.pop()
                    
class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack();
        for(String i: tokens){
            if(i.equals("+") || i.equals("-") || i.equals("*") || i.equals("/")){
                int a = stack.pop();
                int b = stack.pop();
                int temp = 0;
                if(i.equals("+"))
                    temp = a+b;
                else if(i.equals("-"))
                    temp = b-a;
                else if(i.equals("*"))
                    temp = a*b;
                else if(i.equals("/"))
                    temp = b/a;
                stack.push(temp);
            }
            else
                stack.push(Integer.parseInt(i));
        }
        return stack.pop();
    }
}
class Solution {
public:
    int stoi(string s){
        int n = 0;
        int i = 0;
        bool neg = false;
        if(s[0] == '-'){
            i++;
            neg = true;
        }
        for(; i < s.size(); i++){
            n = n*10 + (s[i]-'0');
        }
        if(neg) n = -n;
        return n;
    }
    int evalRPN(vector<string>& tokens) {
        stack<int>s;
        int n = tokens.size();
        for(int i = 0; i < n; i++){
            string str = tokens[i];
            if(str == "*"){
                int n1 = s.top();
                s.pop();
                int n2 = s.top();
                s.pop();
                int res = n2*n1;
                s.push(res);
            }
            else if(str == "+") {
                int n1 = s.top();
                s.pop();
                int n2 = s.top();
                s.pop();
                int res = n2+n1;
                s.push(res);
            }
            else if(str == "/"){
                int n1 = s.top();
                s.pop();
                int n2 = s.top();
                s.pop();
                int res = n2/n1;
                s.push(res);
            }
            else if(str == "-"){
                int n1 = s.top();
                s.pop();
                int n2 = s.top();
                s.pop();
                int res = n2-n1;
                s.push(res);
            }
            else{
                int num = stoi(str);
                s.push(num);
            }
        }
        return s.top();
    }
};
const ops = new Set(['+', '-', '*', '/']);

/**
 * @param {string[]} tokens
 * @return {number}
 */
var evalRPN = function(tokens) {
    const stack = [];

    for (const token of tokens) {
        if (!ops.has(token)) {
            stack.push(Number(token));
            continue;
        }

        const val1 = stack.pop();
        const val2 = stack.pop();
        let toPush;

        if (token === '+') {
            toPush = val1 + val2;
        }

        if (token === '-') {
            toPush = val2 - val1;
        }

        if (token === '*') {
            toPush = val1 * val2;
        }

        if (token === '/') {
            toPush = Math.trunc(val2 / val1);
        }

        stack.push(toPush);
    }

    return stack[0] || 0;
};
Evaluate Reverse Polish Notation