1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/为运算表达式设计优先级 [different-ways-to-add-parentheses].html

39 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个由数字和运算符组成的字符串&nbsp;<code>expression</code> ,按不同优先级组合数字和运算符,计算并返回所有可能组合的结果。你可以 <strong>按任意顺序</strong> 返回答案。</p>
<p>生成的测试用例满足其对应输出值符合 32 位整数范围,不同结果的数量不超过 <code>10<sup>4</sup></code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>expression = "2-1-1"
<strong>输出:</strong>[0,2]
<strong>解释:</strong>
((2-1)-1) = 0
(2-(1-1)) = 2
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>expression = "2*3-4*5"
<strong>输出:</strong>[-34,-14,-10,-10,10]
<strong>解释:</strong>
(2*(3-(4*5))) = -34
((2*3)-(4*5)) = -14
((2*(3-4))*5) = -10
(2*((3-4)*5)) = -10
(((2*3)-4)*5) = 10
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= expression.length &lt;= 20</code></li>
<li><code>expression</code> 由数字和算符 <code>'+'</code><code>'-'</code><code>'*'</code> 组成。</li>
<li>输入表达式中的所有整数值在范围 <code>[0, 99]</code>&nbsp;</li>
</ul>