652. Implement a Basic Calculator II

MediumStackStackMathString

Given a string s representing an arithmetic expression of non-negative integers and the operators +, -, *, / (with usual precedence and possible spaces, no parentheses), evaluate it and return the integer result. Division truncates toward zero. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the evaluated result.

Examples

Example 1
Input: {"s":"3+2*2"}
Output: 7
Explanation: Multiplication first.
Example 2
Input: {"s":" 3/2 "}
Output: 1
Explanation: Integer division.
Example 3
Input: {"s":" 3+5 / 2 "}
Output: 5
Explanation: 3 + (5/2) = 5.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →