java.lang.Object
g2201_2300.s2206_divide_array_into_equal_pairs.Solution

public class Solution extends Object
2206 - Divide Array Into Equal Pairs.<p>Easy</p> <p>You are given an integer array <code>nums</code> consisting of <code>2 * n</code> integers.</p> <p>You need to divide <code>nums</code> into <code>n</code> pairs such that:</p> <ul> <li>Each element belongs to <strong>exactly one</strong> pair.</li> <li>The elements present in a pair are <strong>equal</strong>.</li> </ul> <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> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,2,3,2,2,2]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.</p> <p>If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,4]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong></p> <p>There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>nums.length == 2 * n</code></li> <li><code>1 <= n <= 500</code></li> <li><code>1 <= nums[i] <= 500</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • divideArray

      public boolean divideArray(int[] nums)