Evaluate a Mathematical Expression

Problem Evaluate an arithmetic expression string with +, -, *, / and nested parentheses, e.g. (((2-2)*12+22)-((22-11)*11)/2), honoring precedence.

Input / Output

  • Input: expression string. Output: numeric result.

Constraints

  • Length up to 10^4; multi-digit numbers, optional whitespace, unary minus (clarify!), integer vs float division (clarify) — the clarifications are part of the grade.

Example

  • "(3+2)2" → 10; "2+34" → 14 (precedence); "((2-2)*12+22)" → 22.
asked …
LeaderboardSalaryAccount