The string s holds an arithmetic expression built from non-negative whole numbers, +, -, round brackets and spaces. Work out its value and return it.
A - can also stand in front of a number or a bracket with nothing before it, at the very start of s or right after a (, to negate it: -5 and -(2 + 3) are both allowed. A + is only ever used between two values.
Evaluate it yourself: don't hand the string to a built-in that evaluates expressions, such as eval().
Left to right: 7 - 3 = 4, then 4 + 10 = 14.
The inner bracket is 11, so 4 - 11 = -7. The leading - turns that into 7, and 7 + 1 = 8. The space at the start of s is just a space.
1 - 20 = -19, then 5 - (-19) = 24, then 12 - 24 = -12. A bracket may hold a single number.
Constraints
1 <= s.length <= 3 * 10⁵s is made of digits, +, -, (, ) and spaces. Spaces may appear anywhere except inside a number, including at the start and end of s.s is a valid expression: brackets match, no bracket is empty, and no two operators are next to each other.- may negate the value after it; + never does (+3 alone is not valid).10⁴ deep.s, every partial result as you work through it, and the answer fit in a signed 32-bit integer.With only + and -, every number ends up either added to or subtracted from the answer. A - in front of a bracket flips the sign of everything inside it, so all you really need is the sign in force when each number is read.
14