439. Ternary Expression Parser

Problem

Parse and evaluate a ternary expression string like 'T?2:3' or 'F?1:T?4:5'.

Given a ternary expression (a conditional expression with format condition ? value1 : value2), parse and evaluate it. The expression may be nested.

Return the result of evaluating the ternary expression.

Examples
Input: "T?2:3"
Output: "2"
Hints
Related Problems

439. Ternary Expression Parser

Parse and evaluate a ternary expression string like 'T?2:3' or 'F?1:T?4:5'.