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)/执行操作后不同元素的最大数量 [maximum-number-of-distinct-elements-after-operations].html
2025-01-09 01:30:35 +08:00

46 lines
1.5 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>nums</code> 和一个整数 <code>k</code></p>
<p>你可以对数组中的每个元素&nbsp;<strong>最多</strong> 执行 <strong>一次&nbsp;</strong>以下操作:</p>
<ul>
<li>将一个在范围&nbsp;<code>[-k, k]</code> 内的整数加到该元素上。</li>
</ul>
<p>返回执行这些操作后,<code>nums</code> 中可能拥有的不同元素的&nbsp;<strong>最大&nbsp;</strong>数量。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [1,2,2,3,3,4], k = 2</span></p>
<p><strong>输出:</strong> <span class="example-io">6</span></p>
<p><strong>解释:</strong></p>
<p>对前四个元素执行操作,<code>nums</code> 变为 <code>[-1, 0, 1, 2, 3, 4]</code>,可以获得 6 个不同的元素。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [4,4,4,4], k = 1</span></p>
<p><strong>输出:</strong> <span class="example-io">3</span></p>
<p><strong>解释:</strong></p>
<p><code>nums[0]</code> 加 -1以及对 <code>nums[1]</code> 加 1<code>nums</code> 变为 <code>[3, 5, 4, 4]</code>,可以获得 3 个不同的元素。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>