Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions solution/2200-2299/2206.Divide Array Into Equal Pairs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,6 @@ func divideArray(nums []int) bool {
}
```

#### TypeScript

```ts
function divideArray(nums: number[]): boolean {
const cnt: Record<number, number> = {};
for (const x of nums) {
cnt[x] = (cnt[x] || 0) + 1;
}
return Object.values(cnt).every(x => x % 2 === 0);
}
```

#### Rust

```rust
Expand All @@ -172,6 +160,24 @@ impl Solution {
}
```

#### TypeScript

```ts
function divideArray(nums: number[]): boolean {
const cnt = Array(501).fill(0);

for (const x of nums) {
cnt[x]++;
}

for (const x of cnt) {
if (x & 1) return false;
}

return true;
}
```

#### JavaScript

```js
Expand All @@ -180,11 +186,17 @@ impl Solution {
* @return {boolean}
*/
var divideArray = function (nums) {
const cnt = {};
const cnt = Array(501).fill(0);

for (const x of nums) {
cnt[x] = (cnt[x] || 0) + 1;
cnt[x]++;
}
return Object.values(cnt).every(x => x % 2 === 0);

for (const x of cnt) {
if (x & 1) return false;
}

return true;
};
```

Expand Down
46 changes: 29 additions & 17 deletions solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tags:
<pre>
<strong>Input:</strong> nums = [3,2,3,2,2,2]
<strong>Output:</strong> true
<strong>Explanation:</strong>
<strong>Explanation:</strong>
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.
</pre>
Expand All @@ -48,7 +48,7 @@ If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy al
<pre>
<strong>Input:</strong> nums = [1,2,3,4]
<strong>Output:</strong> false
<strong>Explanation:</strong>
<strong>Explanation:</strong>
There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.
</pre>

Expand Down Expand Up @@ -142,18 +142,6 @@ func divideArray(nums []int) bool {
}
```

#### TypeScript

```ts
function divideArray(nums: number[]): boolean {
const cnt: Record<number, number> = {};
for (const x of nums) {
cnt[x] = (cnt[x] || 0) + 1;
}
return Object.values(cnt).every(x => x % 2 === 0);
}
```

#### Rust

```rust
Expand All @@ -170,6 +158,24 @@ impl Solution {
}
```

#### TypeScript

```ts
function divideArray(nums: number[]): boolean {
const cnt = Array(501).fill(0);

for (const x of nums) {
cnt[x]++;
}

for (const x of cnt) {
if (x & 1) return false;
}

return true;
}
```

#### JavaScript

```js
Expand All @@ -178,11 +184,17 @@ impl Solution {
* @return {boolean}
*/
var divideArray = function (nums) {
const cnt = {};
const cnt = Array(501).fill(0);

for (const x of nums) {
cnt[x] = (cnt[x] || 0) + 1;
cnt[x]++;
}
return Object.values(cnt).every(x => x % 2 === 0);

for (const x of cnt) {
if (x & 1) return false;
}

return true;
};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
* @return {boolean}
*/
var divideArray = function (nums) {
const cnt = {};
const cnt = Array(501).fill(0);

for (const x of nums) {
cnt[x] = (cnt[x] || 0) + 1;
cnt[x]++;
}
return Object.values(cnt).every(x => x % 2 === 0);

for (const x of cnt) {
if (x & 1) return false;
}

return true;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
function divideArray(nums: number[]): boolean {
const cnt: Record<number, number> = {};
const cnt = Array(501).fill(0);

for (const x of nums) {
cnt[x] = (cnt[x] || 0) + 1;
cnt[x]++;
}
return Object.values(cnt).every(x => x % 2 === 0);

for (const x of cnt) {
if (x & 1) return false;
}

return true;
}