297. Basic Calculator III

HardStack

Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, `'+'`, `'-'`, `'*'`, `'/'` operators, and open `'('` and closing parentheses `')'`. The integer division should **truncate toward zero**. You may assume that the given expression is always valid. All intermediate results will be in the range of `[-2^31, 2^31 - 1]`.

Examples

Input: 1+1

Output: 2

Explanation: Simple addition.

Constraints

  • 1 <= s.length <= 10^4
  • s consists of digits, '+', '-', '*', '/', '(', and ')'.
  • s is a valid expression.
Loading...

Run checks all cases above. Submit evaluates all test cases.