536.Evaluate Expressions with Operator Precedence
Easy
Given three integers
a, b and c, return the values of four expressions in order: a + b * c, (a + b) * c, a - b - c and a - (b - c).
Arithmetic operators do not simply run left to right. Operator precedenceOperator PrecedenceThe ranking that decides which operator is applied first: *, / and % come before + and −. decides which operator goes first, associativityAssociativityFor operators of equal precedence, the direction they group in. + and − group left to right. breaks ties between operators of the same rank, and brackets override both. The four expressions are chosen in pairs so each pair differs only by where the brackets are.
Example 1:
Input: a = 2, b = 3, c = 4
Output: [14,20,-5,3]
Example 2:
Input: a = 10, b = 0, c = 7
Output: [10,70,3,17]
+ 5 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ a, b, c ≤ 1000
a =
2
b =
3
c =
4