mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
37 lines
1.0 KiB
HTML
37 lines
1.0 KiB
HTML
<p>给你一个由数字和运算符组成的字符串 <code>expression</code> ,按不同优先级组合数字和运算符,计算并返回所有可能组合的结果。你可以 <strong>按任意顺序</strong> 返回答案。</p>
|
||
|
||
<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>
|