Approach #1: String. [Java]

class Solution {
public List<String> wordSubsets(String[] A, String[] B) {
int[] init = new int[26], temp;
for (String b : B) {
temp = counter(b);
for (int i = 0; i < 26; ++i) {
init[i] = Math.max(init[i], temp[i]);
}
}
List<String> ret = new ArrayList<>();
for (String a : A) {
temp = counter(a);
int i = 0;
for (i = 0; i < 26; ++i) {
if (temp[i] < init[i]) break;
}
if (i == 26) ret.add(a);
}
return ret;
} public int[] counter(String b) {
int[] temp = new int[26];
for (int i = 0; i < b.length(); ++i) {
temp[b.charAt(i)-'a']++;
}
return temp;
}
}

  

05-27 11:26