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)/删除并获得点数 [delete-and-earn].html
2022-03-29 12:43:11 +08:00

38 lines
1.2 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>nums</code> ,你可以对它进行一些操作。</p>
<p>每次操作中,选择任意一个 <code>nums[i]</code> ,删除它并获得 <code>nums[i]</code> 的点数。之后,你必须删除 <strong>所有 </strong>等于 <code>nums[i] - 1</code><code>nums[i] + 1</code> 的元素。</p>
<p>开始你拥有 <code>0</code> 个点数。返回你能通过这些操作获得的最大点数。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [3,4,2]
<strong>输出:</strong>6
<strong>解释:</strong>
删除 4 获得 4 个点数,因此 3 也被删除。
之后,删除 2 获得 2 个点数。总共获得 6 个点数。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [2,2,3,3,3,4]
<strong>输出:</strong>9
<strong>解释:</strong>
删除 3 获得 3 个点数,接着要删除两个 2 和 4 。
之后,再次删除 3 获得 3 个点数,再次删除 3 获得 3 个点数。
总共获得 9 个点数。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
</ul>