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)/移除盒子 [remove-boxes].html
2022-03-29 12:43:11 +08:00

44 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>给出一些不同颜色的盒子<meta charset="UTF-8" />&nbsp;<code>boxes</code>&nbsp;,盒子的颜色由不同的正数表示。</p>
<p>你将经过若干轮操作去去掉盒子,直到所有的盒子都去掉为止。每一轮你可以移除具有相同颜色的连续 <code>k</code> 个盒子(<code>k&nbsp;&gt;= 1</code>),这样一轮之后你将得到 <code>k * k</code> 个积分。</p>
<p>返回 <em>你能获得的最大积分和</em>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>boxes = [1,3,2,2,2,3,4,3,1]
<strong>输出:</strong>23
<strong>解释:</strong>
[1, 3, 2, 2, 2, 3, 4, 3, 1]
----&gt; [1, 3, 3, 4, 3, 1] (3*3=9 分)
----&gt; [1, 3, 3, 3, 1] (1*1=1 分)
----&gt; [1, 1] (3*3=9 分)
----&gt; [] (2*2=4 分)
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>boxes = [1,1,1]
<strong>输出:</strong>9
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>boxes = [1]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= boxes.length &lt;= 100</code></li>
<li><code>1 &lt;= boxes[i]&nbsp;&lt;= 100</code></li>
</ul>