Hard

Quiz

#224 Basic Calculator

APPROACH

Evaluate the arithmetic expression in string s and return its integer result.

Note: Using any built-in expression evaluator (such as eval()) is not permitted.

Example 1:

Input: s = "1 + 1"
Output: 2

Example 2:

Input: s = " 2-1 + 2 "
Output: 3

Example 3:

Input: s = "(1+(4+5+2)-3)+(6+8)"
Output: 23
1 of 4
1:00

What is the optimal approach for this problem?