码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 1002. Find Common Characters

时间:2019-03-11 22:34:00      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:pre   nts   comm   cti   har   def   leetcode   sel   self   

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

 

Leetcode 1002. Find Common Characters

标签:pre   nts   comm   cti   har   def   leetcode   sel   self   

原文地址:https://www.cnblogs.com/zywscq/p/10513632.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!