1002. Find Common Characters

Photo by Glen Carrie on Unsplash

1002. Find Common Characters

class Solution:
    def commonChars(self, words: List[str]) -> List[str]:
        d = defaultdict(int)
        for e in words[0]:
            d[e] += 1

        for word in words:
            c = Counter(word)
            for e in d.keys():
                d[e] = min(d[e], c[e])

        ans = [x for x in d.keys() for _ in range(d[x])]
        return ans