1002. 查找常用字符
给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。
你可以按任意顺序返回答案。
两种写法,一个用set遍历,一个用list遍历,2者的差距在哪
class Solution(object):
def commonChars(self, A):
"""
:type A: List[str]
:rtype: List[str]
"""
key = A[0]
result = []
for i in set(key):
num = min([k.count(i) for k in A])
result += [i]*num
return(result)
class Solution(object):
def commonChars(self, A):
"""
:type A: List[str]
:rtype: List[str]
"""
key = A[0]
result = []
for i in list(set(key)):
num = min([k.count(i) for k in A])
result += [i]*num
return(result)