Leetcode 1002. Find Common Characters

python可重集合操作

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

 

posted @ 2019-03-11 22:18  周洋  阅读(261)  评论(0编辑  收藏  举报