Given an array A
of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.
You may return the answer in any order.
开一个26大小的数组,然后对所有单词的字符统计出现过的次数,然后取min值。最后剩下来的就是共有的字符
class Solution(object): def commonChars(self, A): """ :type A: List[str] :rtype: List[str] """ count = [0] * 26 for c in A[0]: count[ord(c) - ord('a')] += 1 for s in A: temp_count = [0] * 26 for c in s: temp_count[ord(c) - ord('a')] += 1 for i in range(len(temp_count)): count[i] = min(count[i], temp_count[i]) ans = [] for i in range(len(count)): while count[i] > 0: ans.append(chr(i + ord('a'))) count[i] -= 1 return ans