← 返回 bytedance 的题目列表Basic Calculator II: Evaluate Expression with +, -, *, / Operators
类型:online_judge
bytedance
Given a string s which represents a mathematical expression, evaluate the expression and return its value. The expression contains non-negative integers, +, -, *, and / operators as well as spaces. The operators have the usual precedence: * and / have higher precedence than + and -. Assume that the input is always a valid expression.
Examples:
Input: "3+2*2"
Output: 7
Input: " 3/2 "
Output: 1
Input: " 3+5 / 2 "
Output: 5
Constraints:
1 <= s.length <= 10^5
s consists of integers and operators ('+', '-', '*', '/') separated by some number of spaces. Integers are valid and fit within the 32-bit signed integer range.
Example
Input
3+2*2