Basic Calculator
Hard
Stack
Grind 75
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().

Constraints:

  • 1 <= s.length <= 3 * 105
  • s consists of digits, '+', '-', '(', ')', and ' '
  • s represents a valid expression
  • All intermediate results will be in the range [-231, 231 - 1]