leetcode1002

 1 class Solution:
 2     def commonChars(self, A: 'List[str]') -> 'List[str]':
 3         n = len(A)
 4         if n == 1:
 5             return A
 6         basestr = A[0]
 7         baselist = {}
 8         
 9         for b in basestr:
10             if b not in baselist.keys():
11                 baselist.update({b:1})
12             else:
13                 baselist.update({b:baselist[b]+1})
14         for i in range(1,n):
15             cur = A[i]
16             curlist = {}
17             for c in cur:
18                 if c not in curlist:
19                     curlist.update({c:1})
20                 else:
21                     curlist.update({c:curlist[c]+1})
22             for d in baselist.keys():
23                 if d not in curlist.keys():
24                     baselist.update({d:0})
25                 else:
26                     baselist.update({d:min(baselist[d],curlist[d])})
27         result = list()
28         for e in baselist.keys():
29             for f in range(baselist[e]):
30                 result.append(e)
31 
32         return result
原文地址:https://www.cnblogs.com/asenyang/p/10464938.html