mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一正整数数组<strong> </strong><code>nums</code><strong>,</strong><code>nums</code> 中的相邻整数将进行浮点除法。例如, [2,3,4] -> 2 / 3 / 4 。</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>例如,<code>nums = [2,3,4]</code>,我们将求表达式的值 <code>"2/3/4"</code>。</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p>但是,你可以在任意位置添加任意数目的括号,来改变算数的优先级。你需要找出怎么添加括号,以便计算后的表达式的值为最大值。</p>
 | 
						||
 | 
						||
<p>以字符串格式返回具有最大值的对应表达式。</p>
 | 
						||
 | 
						||
<p><strong>注意:</strong>你的表达式不应该包含多余的括号。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong> [1000,100,10,2]
 | 
						||
<strong>输出:</strong> "1000/(100/10/2)"
 | 
						||
<strong>解释: </strong>1000/(100/10/2) = 1000/((100/10)/2) = 200
 | 
						||
但是,以下加粗的括号 "1000/(<strong>(</strong>100/10<strong>)</strong>/2)" 是冗余的,
 | 
						||
因为他们并不影响操作的优先级,所以你需要返回 "1000/(100/10/2)"。
 | 
						||
 | 
						||
其他用例:
 | 
						||
1000/(100/10)/2 = 50
 | 
						||
1000/(100/(10/2)) = 50
 | 
						||
1000/100/10/2 = 0.5
 | 
						||
1000/100/(10/2) = 2
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong> nums = [2,3,4]
 | 
						||
<strong>输出:</strong> "2/(3/4)"
 | 
						||
<strong>解释:</strong> (2/(3/4)) = 8/3 = 2.667
 | 
						||
可以看出,在尝试了所有的可能性之后,我们无法得到一个结果大于 2.667 的表达式。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>说明:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= nums.length <= 10</code></li>
 | 
						||
	<li><code>2 <= nums[i] <= 1000</code></li>
 | 
						||
	<li>对于给定的输入只有一种最优除法。</li>
 | 
						||
</ul>
 |