-
Notifications
You must be signed in to change notification settings - Fork 8
/
3. Compare Strings.py
63 lines (47 loc) · 1.36 KB
/
3. Compare Strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import collections
def solve(A, B):
#A="abcd,aabc,bd"
#B="aaa,aa"
wordsA = A.split(",")
wordsB = B.split(",")
print('wordsA',wordsA)
#loop on smaller one
#if len(wordsA)>len(wordsB):
# wordsA,wordsB=wordsB,wordsA
res=[]
for b in wordsB: #abcd
print('b:',b)
countSmaller=0
print('min b',min(b))
myB=b.count(min(b))
print('count of min',myB)
for a in wordsA: #aaa
print('a:',a)
print('min a', min(a))
myA = a.count(min(a))
print('count of min', myB)
if myA<myB:
countSmaller+=1
print('countSmaller is',countSmaller)
res.append(countSmaller)
print('res',res)
return res
assert (solve("abcd,aabc,bd","aaa,aa")==[3,2])
assert (solve("abcd","aaa")==[1])
assert (solve("a","bb")==[1])
""" for b in wordsB: #abcd
print('b:',b)
countSmaller=0
myB=collections.Counter(b)
for a in wordsA: #aaa
print('a:',a)
#if b[0] ==a[0]
myA=collections.Counter(a) #
if b[0] == a[0]: #a
if myA[a[0]]<myB[b[0]]: #1<3
countSmaller+=1
elif myA[a[0]]<myB[b[0]]:
countSmaller+=1
print('countSmaller is',countSmaller)
res.append(countSmaller)
"""