-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathismerge_02.py
More file actions
36 lines (28 loc) · 884 Bytes
/
ismerge_02.py
File metadata and controls
36 lines (28 loc) · 884 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
32
33
34
35
36
import collections
def is_merge(s, part1, part2):
if collections.Counter(s) != collections.Counter(part1 + part2):
return False
i, j = 0, 0
while j < len(part1):
if i == len(s):
return False
if part1[j] == s[i]:
j += 1
i += 1
i, j = 0, 0
while j < len(part2):
if i == len(s):
return False
if part2[j] == s[i]:
j += 1
i += 1
return True
if __name__ == '__main__':
# is_merge('codewars', 'code', 'wars')
# is_merge('codewars', 'cdw', 'oears')
# is_merge('codewars', 'cod', 'wars')
# is_merge('codewars', '', 'codewars')
# is_merge('Making progress', 'Mak pross', 'inggre')
# is_merge('codewars', 'cwdr', 'oeas')
# is_merge('Bananas from Bahamas', 'Bahas', 'Bananas from am')
is_merge('codewars', 'code', 'wasr')