Back to DSA
Basic Calculator
hardWrite a calculator that evaluates a string expression containing non-negative integers, the operators + and -, parentheses for grouping, and optional spaces. The expression is guaranteed to be well-formed. Return the computed integer result.
Examples
Example 1:
Input:
s = "5 - 3 + 2"Output:
4 Example 2:
Input:
s = "(2+(3+4+1)-2)+(7+9)"Output:
24Hints
1234567