Skip to content
LC-1002 Easy LeetCode

1002. Find Common Characters

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 75% Topics: Array, Hash Table, String
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n * l)
# Space: O(1)

import collections


class Solution(object):
    def commonChars(self, A):
        """
        :type A: List[str]
        :rtype: List[str]
        """
        result = collections.Counter(A[0])
        for a in A:
            result &= collections.Counter(a)
        return list(result.elements())

Solution from kamyu104/LeetCode-Solutions · MIT