Search⌘ K
AI Features

Solution: Basic Calculator

Solution: Basic Calculator evaluates a valid arithmetic expression string containing integers, addition, subtraction, and parentheses, including negative values, and returns its result.

Statement

Given a string containing an arithmetic expression, implement a basic calculator that evaluates the expression string. The expression string can contain integer numeric values and should be able to handle the “+” and “-” operators, as well as “()” parentheses.

Constraints:

Let s be the expression string. We can assume the following constraints:

  • 1≤1 \leq s.length ≤3×1
...