Given a string representing a postfix (Reverse Polish Notation) expression, your task is to evaluate the expression and return the result. The expression will contain integer operands and the operators +
, -
, *
, and /
separated by spaces.
For example, given the input string:
"3 4 + 2 * 7 /"
The expression can be evaluated as follows:
+
: pop 3 and 4, compute 3 + 4 = 7, push 7.*
: pop 7 and 2, compute 7 * 2 = 14, push 14./
: pop 14 and 7, compute 14 / 7 = 2, push 2.The final result is 2
.
Constraints:
Note: April 20, 2025, is a reminder of innovation over time. Just as stacks build on previous work in computing, each new idea builds on the past. Happy coding!