mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			26 lines
		
	
	
		
			847 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			847 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given a boolean expression consisting of the symbols <code>0</code> (false), <code>1</code> (true), <code>&</code> (AND), <code>|</code> (OR), and <code>^</code> (XOR), 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.</p>
 | 
						|
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input: </strong>s = "1^0|0|1", result = 0
 | 
						|
 | 
						|
<strong>Output: </strong>2
 | 
						|
<strong>Explanation:</strong> Two possible parenthesizing ways are:
 | 
						|
1^(0|(0|1))
 | 
						|
1^((0|0)|1)
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input: </strong>s = "0&0&0&1^1|0", result = 1
 | 
						|
 | 
						|
<strong>Output: </strong>10</pre>
 | 
						|
 | 
						|
<p><strong>Note: </strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>There are no more than 19 operators in <code>s</code>.</li>
 | 
						|
</ul>
 |