-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel10.py
More file actions
34 lines (23 loc) · 712 Bytes
/
level10.py
File metadata and controls
34 lines (23 loc) · 712 Bytes
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
#Given two strings, find the number of common characters between them.
def commonCharacterCount(s1, s2):
counter = 0
s2_l = [i for i in s2]
for i in s1:
if i in s2_l:
rem = s2_l.index(i)
counter += 1
s2_l.remove(s2_l[rem])
elif i not in s2_l:
continue
return counter
print(commonCharacterCount("abca", "xyzbac"))
#alternate solution
# def commonCharacterCount(s1, s2):
# count = 0
# s1_ls, s2_ls = [i for i in s1], [i for i in s2]
# for i in range(len(s1_ls)):
# if s1_ls[i] in s2_ls:
# count += 1
# a = s2_ls.index(s1_ls[i])
# s2_ls.pop(a)
# return count