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)/K 和数对的最大数目 [max-number-of-k-sum-pairs].html
2022-03-29 12:43:11 +08:00

37 lines
1.1 KiB
HTML
Raw 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> 和一个整数 <code>k</code></p>
<p>每一步操作中,你需要从数组中选出和为 <code>k</code> 的两个整数,并将它们移出数组。</p>
<p>返回你可以对数组执行的最大操作数。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3,4], k = 5
<strong>输出:</strong>2
<strong>解释:</strong>开始时 nums = [1,2,3,4]
- 移出 1 和 4 ,之后 nums = [2,3]
- 移出 2 和 3 ,之后 nums = []
不再有和为 5 的数对,因此最多执行 2 次操作。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [3,1,3,4,3], k = 6
<strong>输出:</strong>1
<strong>解释:</strong>开始时 nums = [3,1,3,4,3]
- 移出前两个 3 之后nums = [1,4,3]
不再有和为 6 的数对,因此最多执行 1 次操作。</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
<li><code>1 <= k <= 10<sup>9</sup></code></li>
</ul>