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)/戳气球 [burst-balloons].html

33 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><code>n</code> 个气球,编号为<code>0</code><code>n - 1</code>,每个气球上都标有一个数字,这些数字存在数组&nbsp;<code>nums</code>&nbsp;中。</p>
<p>现在要求你戳破所有的气球。戳破第 <code>i</code> 个气球,你可以获得&nbsp;<code>nums[i - 1] * nums[i] * nums[i + 1]</code> 枚硬币。&nbsp;这里的 <code>i - 1</code><code>i + 1</code> 代表和&nbsp;<code>i</code>&nbsp;相邻的两个气球的序号。如果 <code>i - 1</code><code>i + 1</code> 超出了数组的边界,那么就当它是一个数字为 <code>1</code> 的气球。</p>
<p>求所能获得硬币的最大数量。</p>
<p>&nbsp;</p>
<strong>示例 1</strong>
<pre>
<strong>输入:</strong>nums = [3,1,5,8]
<strong>输出:</strong>167
<strong>解释:</strong>
nums = [3,1,5,8] --&gt; [3,5,8] --&gt; [3,8] --&gt; [8] --&gt; []
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,5]
<strong>输出:</strong>10
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= n &lt;= 300</code></li>
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
</ul>