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