Basic Calculator
Try to solve the Basic Calculator problem.
We'll cover the following
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:
-
s.length
s
consists of digits, “+”, “-”, “(”, and “)”.s
represents a valid expression.- “+” is not used as a unary operation ( and are invalid).
- “-” could be used as a unary operation ( and are valid).
- There will be no two consecutive operators in the input.
- Every number and running calculation will fit in a signed 32-bit integer.
Examples
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy