We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8eb426e commit e462e40Copy full SHA for e462e40
common_characters.py
@@ -0,0 +1,31 @@
1
+class Solution:
2
+ def commonChars(self, A: List[str]) -> List[str]:
3
+
4
+ ''' wrong approach --
5
+ res, hash_ = [], dict()
6
+ clist = [c for ele in A for c in ele]
7
+ for ch in clist:
8
+ hash_[ch] = hash_.get(ch, 0) + 1
9
+ for ele, c in hash_.items():
10
+ if c%len(A) == 0:
11
+ res.append(ele)
12
+ return res
13
+ '''
14
15
+ #Naive non-pythonic code
16
17
+ fin_res = []
18
+ check = set(A[0])
19
+ for l in check:
20
+ res = min([a.count(l) for a in A])
21
+ print(res)
22
+ fin_res.append([l] * res)
23
+ fi = [i for x in fin_res for i in x]
24
+ return sorted(fi)
25
26
+ #power of list comprehensions
27
28
+ result = [[l] * min([a.count(l) for a in A]) for l in check]
29
+ return sorted([i for e in result for i in e])
30
31
0 commit comments