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. The expression is right-associative: each ? pairs with the nearest unmatched : to its right, and every leaf is a single character that is either a digit 0-9, T, or F.

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'.