From 2e3e7c71eb6625e99d1174d2446c43f12b7a4cfb Mon Sep 17 00:00:00 2001
From: ShengyuanWang <78770936+ShengyuanWang@users.noreply.github.com>
Date: Wed, 23 Mar 2022 23:48:43 -0500
Subject: [PATCH 1/7] update 2206 python
---
.../README.md | 14 +++++++++++++-
.../README_EN.md | 18 +++++++++++++++---
.../Solution.py | 12 ++++++++++++
3 files changed, 40 insertions(+), 4 deletions(-)
create mode 100644 solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
index 0e50ec5da521a..6e2d56d361ba6 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
@@ -51,6 +51,7 @@ nums 可以划分成 (2, 2) ,(3, 3) 和 (2, 2) ,满足所有要求。
## 解法
+首先统计数组里面每个数字出现的次数。因为题目要求的数对属于将两个相等的元素放在一起,所以换句话说就是看每个数字出现的次数是不是偶数次。
@@ -59,7 +60,18 @@ nums 可以划分成 (2, 2) ,(3, 3) 和 (2, 2) ,满足所有要求。
```python
-
+class Solution:
+ def divideArray(self, nums: List[int]) -> bool:
+ dic = {}
+ for num in nums:
+ if num in dic:
+ dic[num] += 1
+ else:
+ dic[num] = 1
+ for num in dic:
+ if dic[num] % 2 != 0:
+ return False
+ return True
```
### **Java**
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
index b72cb5bb25485..931b8527c9ccd 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
@@ -21,7 +21,7 @@
Input: nums = [3,2,3,2,2,2]
Output: true
-Explanation:
+Explanation:
There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.
If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.
@@ -31,7 +31,7 @@ If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy al
Input: nums = [1,2,3,4]
Output: false
-Explanation:
+Explanation:
There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.
@@ -45,13 +45,25 @@ There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy
## Solutions
+The first step is to count the number of times each number appears in the array. Since the question asks for pairs of numbers that are part of putting two equal elements together, in other words to see if each number occurs an even number of times.
### **Python3**
```python
-
+class Solution:
+ def divideArray(self, nums: List[int]) -> bool:
+ dic = {}
+ for num in nums:
+ if num in dic:
+ dic[num] += 1
+ else:
+ dic[num] = 1
+ for num in dic:
+ if dic[num] % 2 != 0:
+ return False
+ return True
```
### **Java**
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py b/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
new file mode 100644
index 0000000000000..baa71ea96fda6
--- /dev/null
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
@@ -0,0 +1,12 @@
+class Solution:
+ def divideArray(self, nums: List[int]) -> bool:
+ dic = {}
+ for num in nums:
+ if num in dic:
+ dic[num] += 1
+ else:
+ dic[num] = 1
+ for num in dic:
+ if dic[num] % 2 != 0:
+ return False
+ return True
From a59647dd132b3b9cbcd146cbd6dec85f574b162a Mon Sep 17 00:00:00 2001
From: Shengyuan Wang <78770936+ShengyuanWang@users.noreply.github.com>
Date: Thu, 24 Mar 2022 01:16:36 -0500
Subject: [PATCH 2/7] Update solution/2200-2299/2206.Divide Array Into Equal
Pairs/README.md
Co-authored-by: Yang Libin
---
.../2200-2299/2206.Divide Array Into Equal Pairs/README.md | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
index 6e2d56d361ba6..47648083b85df 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
@@ -62,12 +62,7 @@ nums 可以划分成 (2, 2) ,(3, 3) 和 (2, 2) ,满足所有要求。
```python
class Solution:
def divideArray(self, nums: List[int]) -> bool:
- dic = {}
- for num in nums:
- if num in dic:
- dic[num] += 1
- else:
- dic[num] = 1
+ dic = Counter(nums)
for num in dic:
if dic[num] % 2 != 0:
return False
From f501b38f4094e0c96639badafb6fd12cd1b582f7 Mon Sep 17 00:00:00 2001
From: ShengyuanWang <78770936+ShengyuanWang@users.noreply.github.com>
Date: Thu, 24 Mar 2022 01:22:43 -0500
Subject: [PATCH 3/7] change into counter
---
.../2206.Divide Array Into Equal Pairs/README_EN.md | 7 +------
.../2206.Divide Array Into Equal Pairs/Solution.py | 7 +------
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
index 931b8527c9ccd..32b06f8b83ade 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
@@ -54,12 +54,7 @@ The first step is to count the number of times each number appears in the array.
```python
class Solution:
def divideArray(self, nums: List[int]) -> bool:
- dic = {}
- for num in nums:
- if num in dic:
- dic[num] += 1
- else:
- dic[num] = 1
+ dic = Counter(nums)
for num in dic:
if dic[num] % 2 != 0:
return False
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py b/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
index baa71ea96fda6..cc2267189cd6d 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
@@ -1,11 +1,6 @@
class Solution:
def divideArray(self, nums: List[int]) -> bool:
- dic = {}
- for num in nums:
- if num in dic:
- dic[num] += 1
- else:
- dic[num] = 1
+ dic = Counter(nums)
for num in dic:
if dic[num] % 2 != 0:
return False
From 88dac38571822d51f532433e9c620e9061f4b6b8 Mon Sep 17 00:00:00 2001
From: Yang Libin
Date: Thu, 24 Mar 2022 16:37:56 +0800
Subject: [PATCH 4/7] Update README.md
---
.../2200-2299/2206.Divide Array Into Equal Pairs/README.md | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
index 47648083b85df..3276decb1e1b6 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
@@ -62,11 +62,8 @@ nums 可以划分成 (2, 2) ,(3, 3) 和 (2, 2) ,满足所有要求。
```python
class Solution:
def divideArray(self, nums: List[int]) -> bool:
- dic = Counter(nums)
- for num in dic:
- if dic[num] % 2 != 0:
- return False
- return True
+ cnt = Counter(nums)
+ return all(v % 2 == 0 for v in cnt.values())
```
### **Java**
From cff6e0e567483f3ad6d5817602d770ab436cff76 Mon Sep 17 00:00:00 2001
From: Yang Libin
Date: Thu, 24 Mar 2022 16:38:18 +0800
Subject: [PATCH 5/7] Update README.md
---
solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
index 3276decb1e1b6..ac6b6a07e751d 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
@@ -51,6 +51,7 @@ nums 可以划分成 (2, 2) ,(3, 3) 和 (2, 2) ,满足所有要求。
## 解法
+
首先统计数组里面每个数字出现的次数。因为题目要求的数对属于将两个相等的元素放在一起,所以换句话说就是看每个数字出现的次数是不是偶数次。
From acb50eb037bc5854401aa538c350571126785659 Mon Sep 17 00:00:00 2001
From: Yang Libin
Date: Thu, 24 Mar 2022 16:38:32 +0800
Subject: [PATCH 6/7] Update README_EN.md
---
.../2206.Divide Array Into Equal Pairs/README_EN.md | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
index 32b06f8b83ade..93202eea81a5e 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
@@ -45,6 +45,7 @@ There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy
## Solutions
+
The first step is to count the number of times each number appears in the array. Since the question asks for pairs of numbers that are part of putting two equal elements together, in other words to see if each number occurs an even number of times.
@@ -54,11 +55,8 @@ The first step is to count the number of times each number appears in the array.
```python
class Solution:
def divideArray(self, nums: List[int]) -> bool:
- dic = Counter(nums)
- for num in dic:
- if dic[num] % 2 != 0:
- return False
- return True
+ cnt = Counter(nums)
+ return all(v % 2 == 0 for v in cnt.values())
```
### **Java**
From 32bf9024e8e435e24912c9271642d21a6150a3f4 Mon Sep 17 00:00:00 2001
From: Yang Libin
Date: Thu, 24 Mar 2022 16:38:59 +0800
Subject: [PATCH 7/7] Update Solution.py
---
.../2206.Divide Array Into Equal Pairs/Solution.py | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py b/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
index cc2267189cd6d..f416904caa8be 100644
--- a/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
+++ b/solution/2200-2299/2206.Divide Array Into Equal Pairs/Solution.py
@@ -1,7 +1,4 @@
class Solution:
def divideArray(self, nums: List[int]) -> bool:
- dic = Counter(nums)
- for num in dic:
- if dic[num] % 2 != 0:
- return False
- return True
+ cnt = Counter(nums)
+ return all(v % 2 == 0 for v in cnt.values())