439. Ternary Expression Parser

Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of digits0-9,?,:,TandF(TandFrepresent True and False respectively).

Example: "F?T:F?T?1:2:F?3:4"
OutPut : "4"

这题有个坑 , 以为遇到T 的时候反正要的值也在栈顶, 不需要在栈里删除false 的值, 但是不行啊, 规规矩矩的写代码, 别偷懒。!


439. Ternary Expression Parser_第1张图片

你可能感兴趣的:(439. Ternary Expression Parser)