← 返回 bytedance 的题目列表Calculator with Basic Operations and Parentheses
类型:online_judge
Calculator
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers, and empty spaces .
The expression string contains only non-negative integers, +, -, *, / operators, open and closing parentheses ( and ), and spaces . The integer division should truncate toward zero.
Input
A string representing a valid arithmetic expression containing non-negative integers, +, -, *, / operators, parentheses, and spaces.
Output
The integer result of the arithmetic expression.
Example
Input: 2*(5+5*2)/3+(6/2+8) Output: 21
Input: (2+6*3+5-(3*14/7+2)*5)+3 Output: -12
Constraints
The expression only contains integers and operators.
The result is guaranteed to fit within a 32-bit signed integer.
Example
Input
2*(5+5*2)/3+(6/2+8)