3 4 + means 3 + 4, and 5 1 2 + * means 5 · (1 + 2).
You are given a list of strings tokens, the items of such an expression in order. Each item is either an integer or one of the operators +, -, *, /. Evaluate the expression and return the result.
Division is integer division that truncates toward zero (so 7 / -2 = -3). The expression is always well formed, there is never a division by zero, and the result as well as every intermediate value fits in a signed 32-bit integer.tokens=["7", "2", "-", "4", "*"] → 20
First 7 - 2 = 5, then 5 * 4 = 20.
tokens=["9", "-4", "/", "3", "+"] → 1
9 / -4 = -2.25, truncated toward zero gives -2. Then -2 + 3 = 1.
tokens=["42"] → 42
tokens[i] is an operator +, -, *, / or an integer from -200 to 200tokens=["7", "2", "-", "4", "*"]
20
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.