Skip to content

Commit b9f8785

Browse files
committed
Add solution #2032
1 parent 5e5bab8 commit b9f8785

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,698 LeetCode solutions in JavaScript
1+
# 1,699 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1558,6 +1558,7 @@
15581558
2028|[Find Missing Observations](./solutions/2028-find-missing-observations.js)|Medium|
15591559
2029|[Stone Game IX](./solutions/2029-stone-game-ix.js)|Medium|
15601560
2030|[Smallest K-Length Subsequence With Occurrences of a Letter](./solutions/2030-smallest-k-length-subsequence-with-occurrences-of-a-letter.js)|Hard|
1561+
2032|[Two Out of Three](./solutions/2032-two-out-of-three.js)|Easy|
15611562
2033|[Minimum Operations to Make a Uni-Value Grid](./solutions/2033-minimum-operations-to-make-a-uni-value-grid.js)|Medium|
15621563
2037|[Minimum Number of Moves to Seat Everyone](./solutions/2037-minimum-number-of-moves-to-seat-everyone.js)|Easy|
15631564
2047|[Number of Valid Words in a Sentence](./solutions/2047-number-of-valid-words-in-a-sentence.js)|Easy|

solutions/2032-two-out-of-three.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* 2032. Two Out of Three
3+
* https://leetcode.com/problems/two-out-of-three/
4+
* Difficulty: Easy
5+
*
6+
* Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all
7+
* the values that are present in at least two out of the three arrays. You may return the
8+
* values in any order.
9+
*/
10+
11+
/**
12+
* @param {number[]} nums1
13+
* @param {number[]} nums2
14+
* @param {number[]} nums3
15+
* @return {number[]}
16+
*/
17+
var twoOutOfThree = function(nums1, nums2, nums3) {
18+
const set1 = new Set(nums1);
19+
const set2 = new Set(nums2);
20+
const set3 = new Set(nums3);
21+
const count = new Map();
22+
23+
for (const num of set1) {
24+
count.set(num, (count.get(num) || 0) + 1);
25+
}
26+
27+
for (const num of set2) {
28+
count.set(num, (count.get(num) || 0) + 1);
29+
}
30+
31+
for (const num of set3) {
32+
count.set(num, (count.get(num) || 0) + 1);
33+
}
34+
35+
const result = [];
36+
for (const [num, freq] of count) {
37+
if (freq >= 2) result.push(num);
38+
}
39+
40+
return result;
41+
};

0 commit comments

Comments
 (0)