[CareerCup] 9.11 Parenthesize the Expression 表示式加括號

Grandyang發表於2015-10-01

 

9.11 Given a boolean expression consisting of the symbols 0,1, &, |, and ^, and a desired boolean result value result, implement a function to count the number of ways of parenthesizing the expression such that it evaluates to result.
 EXAMPLE
 Expression: 1^0|0|1
 Desired result: false (0)
 Output: 2 ways. 1^((0|0)|1) and 1^(0|(0|1)).

相關文章