1/20
Loading...
+-*/Simple Calculator
Let's calculate "3*2+4"! The key here: when we read '+', we must **calculate '*' first**! Let's learn the **Two-Stack algorithm** that compares operator precedence in real-time.
Loading...
Let's calculate "3*2+4"! The key here: when we read '+', we must **calculate '*' first**! Let's learn the **Two-Stack algorithm** that compares operator precedence in real-time.
You are building a simple calculator app. Evaluate the user input expression (arithmetic operations + parentheses) and return the result. **Supported operations:** - Addition(+), Subtraction(-), Multiplication(*), Division(/) - Parentheses () for priority **Operator precedence:** - *, / are evaluated before +, - - Expressions in parentheses are always evaluated first
"3*2+4"
10
Operator precedence: 3*2=6 first -> 6+4=10
"(3+2)*4"
20
Parentheses first: 3+2=5 -> 5*4=20