Loading problem…
You're building a calculator app that needs to evaluate mathematical expressions. The calculator should handle addition, subtraction, parentheses, and spaces, but no multiplication or division.
Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.
Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().
calculate("1 + 1");
// 2
calculate(" 2-1 + 2 ");
// 3
calculate("(1+(4+5+2)-3)+(6+8)");
// 23
calculate("-2+ 1");
// -1This problem models real calculator features: