File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 823
823
2154|[ Keep Multiplying Found Values by Two] ( ./2154-keep-multiplying-found-values-by-two.js ) |Easy|
824
824
2161|[ Partition Array According to Given Pivot] ( ./2161-partition-array-according-to-given-pivot.js ) |Medium|
825
825
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|
826
827
2215|[ Find the Difference of Two Arrays] ( ./2215-find-the-difference-of-two-arrays.js ) |Easy|
827
828
2226|[ Maximum Candies Allocated to K Children] ( ./2226-maximum-candies-allocated-to-k-children.js ) |Medium|
828
829
2235|[ Add Two Integers] ( ./2235-add-two-integers.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments