Medium · Stacks & Queues
Calculate postfix
Given an array tokens that forms a valid postfix (Reverse Polish) expression, where each token is an integer (possibly negative) or one of the operators +, -, * and /, return the value of the expression, with division truncating toward zero.
Examples
Example 1
{
"tokens": ["2", "1", "+", "3", "*"]
}Output: = 9
Example 2
{
"tokens": ["4", "13", "5", "/", "+"]
}Output: = 6
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.