Skip to content

Commit dcf95dc

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

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
|1780|[判断一个数字是否可以表示成三的幂的和](https://leetcode.cn/problems/check-if-number-is-a-sum-of-powers-of-three/)|[JavaScript](./algorithms/check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
176176
|1832|[判断句子是否为全字母句](https://leetcode.cn/problems/check-if-the-sentence-is-pangram/)|[JavaScript](./algorithms/check-if-the-sentence-is-pangram.js)|Easy|
177177
|1945|[字符串转化后的各位数字之和](https://leetcode.cn/problems/sum-of-digits-of-string-after-convert/)|[JavaScript](./algorithms/sum-of-digits-of-string-after-convert.js)|Easy|
178+
|2032|[至少在两个数组中出现的值](https://leetcode.cn/problems/two-out-of-three/)|[JavaScript](./algorithms/two-out-of-three.js)|Easy|
178179
|面试题 04.12|[面试题 04.12. 求和路径](https://leetcode.cn/problems/paths-with-sum-lcci/)|[JavaScript](./algorithms/paths-with-sum-lcci.js)|Medium|
179180
|面试题 02.07|[面试题 02.07. 链表相交](https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/)|[JavaScript](./algorithms/intersection-of-two-linked-lists-lcci.js)|Easy|
180181
|剑指 Offer 05. 替换空格|[剑指 Offer 05. 替换空格](https://leetcode.cn/problems/ti-huan-kong-ge-lcof/)|[JavaScript](./algorithms/ti-huan-kong-ge-lcof.js)|Easy|

algorithms/two-out-of-three.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {number[]} nums1
3+
* @param {number[]} nums2
4+
* @param {number[]} nums3
5+
* @return {number[]}
6+
*/
7+
var twoOutOfThree = function(nums1, nums2, nums3) {
8+
const result = [];
9+
const s1 = new Set(nums1);
10+
const s2 = new Set(nums2);
11+
12+
for (let i = 0; i < nums2.length; i++) {
13+
if (s1.has(nums2[i])) {
14+
result.push(nums2[i]);
15+
}
16+
}
17+
for (let i = 0; i < nums3.length; i++) {
18+
if (s1.has(nums3[i])) {
19+
result.push(nums3[i]);
20+
}
21+
}
22+
for (let i = 0; i < nums3.length; i++) {
23+
if (s2.has(nums3[i])) {
24+
result.push(nums3[i]);
25+
}
26+
}
27+
return [...new Set(result)];
28+
};

0 commit comments

Comments
 (0)