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)/将数组划分成相等数对 [divide-array-into-equal-pairs].html
2022-03-29 12:43:11 +08:00

42 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>给你一个整数数组&nbsp;<code>nums</code>&nbsp;,它包含&nbsp;<code>2 * n</code>&nbsp;个整数。</p>
<p>你需要将&nbsp;<code>nums</code> 划分成&nbsp;<code>n</code>&nbsp;个数对,满足:</p>
<ul>
<li>每个元素 <strong>只属于一个 </strong>数对。</li>
<li>同一数对中的元素 <strong>相等</strong>&nbsp;</li>
</ul>
<p>如果可以将 <code>nums</code>&nbsp;划分成 <code>n</code>&nbsp;个数对,请你返回 <code>true</code>&nbsp;,否则返回 <code>false</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [3,2,3,2,2,2]
<b>输出:</b>true
<b>解释:</b>
nums<code>&nbsp;中总共有 6 个元素,所以它们应该被划分成</code> 6 / 2 = 3 个数对。
nums 可以划分成 (2, 2) (3, 3) 和 (2, 2) ,满足所有要求。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [1,2,3,4]
<b>输出:</b>false
<b>解释:</b>
无法将 nums 划分成 4 / 2 = 2 个数对且满足所有要求。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>nums.length == 2 * n</code></li>
<li><code>1 &lt;= n &lt;= 500</code></li>
<li><code>1 &lt;= nums[i] &lt;= 500</code></li>
</ul>