Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation. The expression string may contain open ( and closing ) parentheses, the plus + or minus - sign, non-negative integers and empty spaces.
30:00
Java
Basic Calculator
hard
Topics
Companies
Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation. The expression string may contain open ( and closing ) parentheses, the plus + or minus - sign, non-negative integers and empty spaces.
Example 1:
Input: "(1+(4+5+2)-3)+(6+8)"
Output: 23
Constraints:
1≤s.length≤3×105
s consists of digits, '+', '-', '(', ')', and ' '.
s represents a valid expression.
All intermediate results fit in a signed 32-bit integer.