A postfix expression (Reverse Polish notation) is a mathematical notation in which every operator follows all of its operands. For example, the postfix expression for (3 + 4) 5 would be 3 4 + 5 .
You are given a string array tokens representing a postfix expression. Evaluate the expression and return the result.
The valid operators are +, -, *, and /. Each operand can be an integer, and division should truncate towards zero.
A postfix expression (Reverse Polish notation) is a mathematical notation in which every operator follows all of its operands. For example, the postfix expression for (3 + 4) 5 would be 3 4 + 5 .
You are given a string array tokens representing a postfix expression. Evaluate the expression and return the result.
The valid operators are +, -, *, and /. Each operand can be an integer, and division should truncate towards zero.
Example:
Input: tokens = ["2", "1", "+", "3", "*"] Output: 9
Explanation:
Step 1: Perform 2 + 1 = 3 Step 2: Perform 3 * 3 = 9 Input: tokens = ["4", "13", "5", "/", "+"] Output: 6
Explanation:
Step 1: Perform 13 / 5 = 2 (truncated towards zero) Step 2: Perform 4 + 2 = 6 Constraints: 1 <= tokens.length <= 10^4 tokens[i] is either an integer or an operator: "+", "-", "*", or "/"
Hey @Aditya-K477 ! this is a very good medium-hard problem asked by many tech giants. Please assign this issue to me to solve .