Skip to content

Commit 861fcdf

Browse files
committed
2032. 至少在两个数组中出现的值
1 parent 12b0836 commit 861fcdf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* @lc app=leetcode.cn id=2032 lang=javascript
3+
*
4+
* [2032] 至少在两个数组中出现的值
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* @param {number[]} nums1
10+
* @param {number[]} nums2
11+
* @param {number[]} nums3
12+
* @return {number[]}
13+
*/
14+
var twoOutOfThree = function(nums1, nums2, nums3) {
15+
const result = [];
16+
const s1 = new Set(nums1);
17+
const s2 = new Set(nums2);
18+
19+
for (let i = 0; i < nums2.length; i++) {
20+
if (s1.has(nums2[i])) {
21+
result.push(nums2[i]);
22+
}
23+
}
24+
for (let i = 0; i < nums3.length; i++) {
25+
if (s1.has(nums3[i])) {
26+
result.push(nums3[i]);
27+
}
28+
}
29+
for (let i = 0; i < nums3.length; i++) {
30+
if (s2.has(nums3[i])) {
31+
result.push(nums3[i]);
32+
}
33+
}
34+
return [...new Set(result)];
35+
};
36+
// @lc code=end
37+

0 commit comments

Comments
 (0)