DIY: Basic Calculator III
Solve the interview question "Basic Calculator III" in this lesson.
We'll cover the following
You are given a string
s containing only positive integers, operators (
'/'), and parentheses
'()'. The intermediate results of the given expression string are in the range [-, - 1]. The expression is guaranteed to be valid and the integer division truncates towards zero.
Your task is to evaluate the given expression string.
- The string consists of only digits,
The input of the function is a string. The following is an example input:
The following is the output of the above input:
calculate(s) function, where the
s is a mathematical expression and returns the integer number.