0439. Ternary Expression Parser
https://leetcode.com/problems/ternary-expression-parser
Description
Given a string expression
representing arbitrarily nested ternary expressions, evaluate the expression, and return the result of it.
You can always assume that the given expression is valid and only contains digits, '?'
, ':'
, 'T'
, and 'F'
where 'T'
is true and 'F'
is false. All the numbers in the expression are one-digit numbers (i.e., in the range [0, 9]
).
The conditional expressions group right-to-left (as usual in most languages), and the result of the expression will always evaluate to either a digit, 'T'
or 'F'
.
Example 1:
Example 2:
Example 3:
Constraints:
5 <= expression.length <= 104
expression
consists of digits,'T'
,'F'
,'?'
, and':'
.It is guaranteed that
expression
is a valid ternary expression and that each number is a one-digit number.
ac
Last updated