image_2021-12-04_16-17-14.png
56.5 KB
#N1002. Find Common Characters
problem link
#solution
problem link
#solution
class Solution {
public List<String> commonChars(String[] words) {
int[][] arr = new int[words.length][26];
int n=0;
for(String word:words){
for(char ch:word.toCharArray()){
arr[n][ch-'a']++;
}
n++;
}
List<String> list = new ArrayList<>();
for(int i=0; i<26; i++){
int k=100;
for(int j=0; j<arr.length; j++){
k=Math.min(k, arr[j][i]);
}
while(k-- >0){
list.add(Character.toString(i+'a'));
}
}
return list;
}
}