def commonChars(self, words: List[str]) -> List[str]:
dict1 = dict.fromkeys(string.ascii_lowercase, 101)
for i in words:
for key in dict1:
if i.count(key)<dict1[key]:
dict1[key] = i.count(key)
result=[]
for key,value in dict1.items():
if value>0:
result.extend([key]*value)
return result
class Solution:
def commonChars(self, words):
# your code here
res = []
keys = set(words[0])
for key in keys:
minnum = min(i.count(key) for i in words)
res += [key] * minnum
return res
def commonChars(words):
res = []
keys = set(words[0])
for key in keys:
minnum = min(i.count(key) for i in words)
res += [key] * minnum
return res
commonChars(["bella","label","roller"])
commonChars(["cool","lock","cook"])