Skip to content

Commit 0a5d727

Browse files
authored
Create 2032-two-out-of-three.js
1 parent b9c069e commit 0a5d727

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

2032-two-out-of-three.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {number[]} nums1
3+
* @param {number[]} nums2
4+
* @param {number[]} nums3
5+
* @return {number[]}
6+
*/
7+
const twoOutOfThree = function(nums1, nums2, nums3) {
8+
const res = []
9+
const hash = {}
10+
for(let e of new Set(nums1)) {
11+
if(hash[e] == null) hash[e] = 0
12+
hash[e] = 1
13+
}
14+
15+
for(let e of new Set(nums2)) {
16+
if(hash[e] == null) hash[e] = 0
17+
hash[e]++
18+
}
19+
20+
21+
for(let e of new Set(nums3)) {
22+
if(hash[e] == null) hash[e] = 0
23+
hash[e]++
24+
}
25+
26+
Object.keys(hash).forEach(k => {
27+
if(hash[k] > 1) res.push(k)
28+
})
29+
30+
31+
return res
32+
};

0 commit comments

Comments
 (0)