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