← Back to problems Solve on LeetCode →

Ternary Expression Parser

LeetCode 439 • Medium • Stack

Given a string of nested ternary expressions T?T:F, evaluate right-to-left with a stack.
Example: T?T?F:5:3F. Scan from the end; on ?, resolve using the condition.

TimeO(n)
SpaceO(n)stack
Step0
stack: []
Ready
Press Play or Step.