Given a string representing a valid postfix expression (also known as Reverse Polish Notation) with integers and the operators +
, -
, *
, and /
(each token separated by a single space), write a function to evaluate the expression and return the result as an integer.
Important Details:
Example:
Explanation: The expression is evaluated as (2 + 1) * 3 = 9
.
Hint: Use a stack to store intermediate results while processing the expression from left to right.
Happy coding on this fine January day!