1
var wordSubsets = function (words1, words2) {
2
this.count = Array(26).fill(0);
3
let tmp = Array(26).fill(0);
4
for (let b of words2) {
5
tmp = counter(b);
6
for (let i = 0; i < 26; i++) count[i] = Math.max(count[i], tmp[i]);
7
}
8
let list = [];
9
for (let a of words1) if (isSub(counter(a))) list.push(a);
10
return list;
11
};
12

13
function isSub(tmp) {
14
for (let i = 0; i < 26; i++) if (tmp[i] < this.count[i]) return false;
15
return true;
16
}
17

18
function counter(s) {
19
let tmp = Array(26).fill(0);
20
for (let c of s) tmp[c.charCodeAt() - 97]++;
21
return tmp;
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0