1
class Solution {
2
public List<String> wordSubsets(String[] words1, String[] words2) {
3
List<String> list = new ArrayList<>();
4
int[] bmax = count("");
5
for (String w2 : words2) {
6
int[] b = count(w2);
7
for (int i = 0; i < 26; i++) {
8
bmax[i] = Math.max(bmax[i], b[i]);
9
}
10
}
11
for (String w1 : words1) {
12
int[] a = count(w1);
13
for (int i = 0; i < 26; i++) {
14
if (a[i] < bmax[i]) {
15
break;
16
}
17
if (i == 25) {
18
list.add(w1);
19
}
20
}
21
}
22
return list;
23
}
24

25
public int[] count(String s) {
26
int[] ans = new int[26];
27
for (char c : s.toCharArray()) {
28
ans[c - 'a']++;
29
}
30
return ans;
31
}
32
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0