22```
33import copy
44
5- def concat_longest_title (titles):
5+ def get_longest_title (titles):
66 adj_list = create_adj_list(titles)
77 global_visit = set()
88 longest_title = list()
@@ -19,7 +19,19 @@ def concat_longest_title(titles):
1919 memo)
2020 if len(local_result) > len(longest_title):
2121 longest_title = copy.deepcopy(local_result)
22- return longest_title
22+ return concat_title(longest_title)
23+
24+ def concat_title(titles):
25+ if len(titles) == 0:
26+ return ''
27+ result = ''
28+ result = titles[0]
29+ for index in range(1, len(titles)):
30+ title = titles[index]
31+ sub_title = title[1:]
32+ result += sub_title
33+ return result
34+
2335
2436def create_adj_list(titles):
2537 firstWord_to_titles_hash = dict()
@@ -62,12 +74,15 @@ def visit_title(title, stack, adj_list, local_visit, global_visit, memo):
6274 if len(stack) > len(result):
6375 result = copy.deepcopy(stack)
6476 stack.pop()
77+ local_visit.remove(title)
6578 memo[title] = result
6679 return result
6780
6881Input = ['OF MICE AND MEN', 'BLACK MASS', 'MEN IN BLACK']
69- Input = ['a b', 'b c', 'c d', 'c e', 'e f']
70- Input = ['a b', 'b c', 'c a']
82+ #Input = ['a b', 'b c', 'c d', 'c e', 'e f']
83+ #Input = ['a b', 'b c', 'c a']
84+ Input = ['e f', 'c e', 'c d','b c', 'a b']
85+ #Input = ['c d','b c', 'a b', 'e f', 'c e']
7186
72- print concat_longest_title (Input)
87+ print get_longest_title (Input)
7388```
0 commit comments