2206. Divide Array Into Equal Pairs Easy
1/**
2 * [2206] Divide Array Into Equal Pairs
3 *
4 * You are given an integer array nums consisting of 2 * n integers.
5 * You need to divide nums into n pairs such that:
6 *
7 * Each element belongs to exactly one pair.
8 * The elements present in a pair are equal.
9 *
10 * Return true if nums can be divided into n pairs, otherwise return false.
11 *
12 * Example 1:
13 *
14 * Input: nums = [3,2,3,2,2,2]
15 * Output: true
16 * Explanation:
17 * There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.
18 * If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.
19 *
20 * Example 2:
21 *
22 * Input: nums = [1,2,3,4]
23 * Output: false
24 * Explanation:
25 * There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.
26 *
27 *
28 * Constraints:
29 *
30 * nums.length == 2 * n
31 * 1 <= n <= 500
32 * 1 <= nums[i] <= 500
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/divide-array-into-equal-pairs/
38// discuss: https://leetcode.com/problems/divide-array-into-equal-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn divide_array(nums: Vec<i32>) -> bool {
44 false
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_2206() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.