Basic Calculator
Given a valid arithmetic expression string s, evaluate it and return its integer result.
The expression may contain non-negative integers, + and - operators, parentheses, and spaces. Spaces should be ignored.
You may not use a built-in expression evaluator.
s = 1 + 1
2
1 + 1 = 2.
s = 2-1 + 2
3
2 - 1 + 2 = 3.
s = 1 - (2 + 3)
-4
The - applies to the whole group: 1 - (2 + 3) = 1 - 5 = -4. Just dropping the parentheses would give 1 - 2 + 3 = 2, so a minus in front of a ( is exactly why the parentheses matter.
s = (1+(4+5+2)-3)+(6+8)
23
The first parenthesized group evaluates to 9, and the second group evaluates to 14.
1 <= s.lengthsis a valid expression containing digits,+,-,(,), and spaces- Every number is a non-negative integer