题目
代码部分(4ms 99.26%)
class Solution {
public List<String> commonChars(String[] A) {
List<String> res = new ArrayList();
if(A == null || A.length == 0) return res;
int[] max = new int[26];
boolean[] flag = new boolean[26];
int len = A.length;
for(int i = 0; i < len; i++){
char[] ch = A[i].toCharArray();
int[] c = new int[26];
for(int j = 0; j < ch.length; j++){
char tmp = ch[j];
c[(int)tmp - 97]++;
}
for(int j = 0; j < 26; j++){
if(c[j] == 0){
flag[j] = true;
}else if( max[j] == 0 && max[j] < c[j]){
max[j] = c[j];
}else if(c[j] > 0 && max[j] > c[j]){
max[j] = c[j];
}
}
}
for(int i = 0; i < 26; i++){
if(!flag[i]){
while(max[i] > 0){
char tmp = (char)(i+97);
res.add(tmp + "");
max[i]--;
}
}
}
return res;
}
}