227. Basic Calculator II
Practice Basic Calculator II for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Evaluate an arithmetic expression given as a string and return its value. The expression contains non-negative integers, the operators + - * / and spaces, but no parentheses. * and / bind tighter than + and -; operators of the same level go left to right. Integer division truncates toward zero. Do not use a built-in eval.
Example
s = "3+2*2" -> 7
s = " 3+5 / 2 " -> 5
s = "1-1-1" -> -1
Constraints
- 1 <= s.length <= 3 * 10^5
- The expression is valid, every number is in [0, 2^31 - 1], and every intermediate result fits in a 32-bit signed integer