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().
Example 1
Input: s = (1+(4+5+2)-3)+(6+8)
Output: 23
Explanation: Work from the innermost parentheses outward: 4 + 5 + 2 = 11, then 1 + 11 - 3 = 9, and 6 + 8 = 14. Finally 9 + 14 = 23.
Example 2
Input: s = 1 + 1
Output: 2
Explanation: Spaces are ignored, so this is simply 1 + 1 = 2.
Example 3
Input: s = 2-1 + 2
Output: 3
Explanation: Ignoring the spaces, the expression is 2 - 1 + 2. Evaluating left to right: 2 - 1 = 1, then 1 + 2 = 3.
Scan left to right accumulating a running result and the sign of the next number. When you meet '(', push the current result and sign, then start fresh; when you meet ')', fold the sub-result back using the pushed sign and result.
Run checks all cases above. Submit evaluates all test cases.