Skip to content

Commit 0aac37e

Browse files
committed
Add solution #2206
1 parent 399fed8 commit 0aac37e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@
823823
2154|[Keep Multiplying Found Values by Two](./2154-keep-multiplying-found-values-by-two.js)|Easy|
824824
2161|[Partition Array According to Given Pivot](./2161-partition-array-according-to-given-pivot.js)|Medium|
825825
2185|[Counting Words With a Given Prefix](./2185-counting-words-with-a-given-prefix.js)|Easy|
826+
2206|[Divide Array Into Equal Pairs](./2206-divide-array-into-equal-pairs.js)|Easy|
826827
2215|[Find the Difference of Two Arrays](./2215-find-the-difference-of-two-arrays.js)|Easy|
827828
2226|[Maximum Candies Allocated to K Children](./2226-maximum-candies-allocated-to-k-children.js)|Medium|
828829
2235|[Add Two Integers](./2235-add-two-integers.js)|Easy|
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* 2206. Divide Array Into Equal Pairs
3+
* https://leetcode.com/problems/divide-array-into-equal-pairs/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums consisting of 2 * n integers.
7+
*
8+
* You need to divide nums into n pairs such that:
9+
* - Each element belongs to exactly one pair.
10+
* - The elements present in a pair are equal.
11+
*
12+
* Return true if nums can be divided into n pairs, otherwise return false.
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @return {boolean}
18+
*/
19+
/**
20+
* @param {number[]} nums
21+
* @return {boolean}
22+
*/
23+
var divideArray = function(nums) {
24+
const map = new Map();
25+
26+
for (const num of nums) {
27+
map.set(num, (map.get(num) || 0) + 1);
28+
}
29+
for (const count of map.values()) {
30+
if (count % 2 !== 0) {
31+
return false;
32+
}
33+
}
34+
35+
return true;
36+
};

0 commit comments

Comments
 (0)