Loading...
You are given an array of strings tokens describing an arithmetic expression in postfix form: every operator comes after the two values it applies to, so the expression needs no parentheses.
Return the value of the expression.
"+", "-", "*" and "/"; every other token is an integer.-7 / 2 is -3, not -4.Input: tokens = ["2","1","+","3","*"]
Output: 9
Explanation: "+" applies to 2 and 1, giving 3. Then "*" applies to that 3 and the following 3, giving 9.
Input: tokens = ["4","13","5","/","+"]
Output: 6
Explanation: "/" applies to 13 and 5, giving 2. Then "+" applies to 4 and 2, giving 6.
Input: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
Output: 22
Explanation: The expression reduces step by step to 22. Note that "-11" is an operand, not the operator "-".
tokens.length ≤104tokens[i] is an operator "+", "-", "*", "/", or an integer in the range [−200,200]Click "Run" to test with sample cases or "Submit" to run all tests.