Basic Calculator
Difficulty: Medium
Description
Given a string expression containing digits and operators (+, -, *, /), evaluate the expression and return the result.
Rules:
- Follow standard operator precedence (multiplication and division before addition and subtraction)
- Division should be integer division (truncate toward zero)
- No parentheses in the expression
Examples
Input: s = "3+2*2"
Output: 7
Explanation: Multiplication first: 3 + (2*2) = 3 + 4 = 7
Input: s = "4-8/2"
Output: 0
Explanation: Division first: 4 - (8/2) = 4 - 4 = 0
Input: s = "14/3*2"
Output: 8
Explanation: Left to right for same precedence: (14/3)*2 = 4*2 = 8
Code
# To be solved