656. Basic Calculator I

HardStackStackMathString

Given a string s representing an expression of non-negative integers, the binary operators + and -, unary minus, parentheses, and spaces, evaluate it and return the integer result. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the evaluated result.

Examples

Example 1
Input: {"s":"(1+(4+5+2)-3)+(6+8)"}
Output: 23
Explanation: Nested parentheses evaluate to 23.
Example 2
Input: {"s":"2-1+2"}
Output: 3
Explanation: Left to right.
Example 3
Input: {"s":"1+1"}
Output: 2
Explanation: Simple addition.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →