2022-03-27 20:56:26 +08:00
|
|
|
|
<p>给你一个由数字和运算符组成的字符串 <code>expression</code> ,按不同优先级组合数字和运算符,计算并返回所有可能组合的结果。你可以 <strong>按任意顺序</strong> 返回答案。</p>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>生成的测试用例满足其对应输出值符合 32 位整数范围,不同结果的数量不超过 <code>10<sup>4</sup></code> 。</p>
|
|
|
|
|
|
2022-03-27 20:56:26 +08:00
|
|
|
|
<p> </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> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li><code>1 <= expression.length <= 20</code></li>
|
|
|
|
|
<li><code>expression</code> 由数字和算符 <code>'+'</code>、<code>'-'</code> 和 <code>'*'</code> 组成。</li>
|
|
|
|
|
<li>输入表达式中的所有整数值在范围 <code>[0, 99]</code> </li>
|
|
|
|
|
</ul>
|