|
| 1 | +<p>You are given an integer array <code>nums</code> consisting of <code>2 * n</code> integers.</p> |
| 2 | + |
| 3 | +<p>You need to divide <code>nums</code> into <code>n</code> pairs such that:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>Each element belongs to <strong>exactly one</strong> pair.</li> |
| 7 | + <li>The elements present in a pair are <strong>equal</strong>.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>Return <code>true</code> <em>if nums can be divided into</em> <code>n</code> <em>pairs, otherwise return</em> <code>false</code>.</p> |
| 11 | + |
| 12 | +<p> </p> |
| 13 | +<p><strong class="example">Example 1:</strong></p> |
| 14 | + |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> nums = [3,2,3,2,2,2] |
| 17 | +<strong>Output:</strong> true |
| 18 | +<strong>Explanation:</strong> |
| 19 | +There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs. |
| 20 | +If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions. |
| 21 | +</pre> |
| 22 | + |
| 23 | +<p><strong class="example">Example 2:</strong></p> |
| 24 | + |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> nums = [1,2,3,4] |
| 27 | +<strong>Output:</strong> false |
| 28 | +<strong>Explanation:</strong> |
| 29 | +There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition. |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p> </p> |
| 33 | +<p><strong>Constraints:</strong></p> |
| 34 | + |
| 35 | +<ul> |
| 36 | + <li><code>nums.length == 2 * n</code></li> |
| 37 | + <li><code>1 <= n <= 500</code></li> |
| 38 | + <li><code>1 <= nums[i] <= 500</code></li> |
| 39 | +</ul> |
0 commit comments