Count Common Words With One Occurrence LeetCode solution in JavaScript

1
var countWords = function (words1, words2) {
2
const map1 = new Map();
3
const map2 = new Map();
4
let count = 0;
5

6
for (const word of words1) {
7
map1.set(word, map1.get(word) + 1 || 1);
8
}
9
for (const word of words2) {
10
map2.set(word, map2.get(word) + 1 || 1);
11
}
12
for (const word of words1) {
13
if (map1.get(word) === 1 && map2.get(word) === 1) count++;
14
}
15

16
return count;
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0