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

37 lines
1.0 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>&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>