Skip to content

Commit bac4fe2

Browse files
committed
Reverted the changes
1 parent 1c6540a commit bac4fe2

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
from typing import List
22

33

4-
def find_longest_common_prefix(strings: List[str]) -> str:
4+
def find_longest_common_prefix(strings: List[str]):
55
"""
66
find_longest_common_prefix returns the longest string common at the start of any two strings in the passed list.
77
88
In the event that an empty list, a list containing one string, or a list of strings with no common prefixes is passed, the empty string will be returned.
99
"""
10-
if len(strings) < 2:
11-
return ""
12-
13-
# PRE-COMPUTE by sorting strings once
14-
strings = sorted(strings)
15-
1610
longest = ""
17-
18-
#compare only strings that are next to eacotherr in sorted order
19-
for i in range(len(strings) - 1):
20-
common = find_common_prefix(strings[i], strings[i + 1])
21-
if len(common) > len(longest):
22-
longest = common
23-
11+
for string_index, string in enumerate(strings):
12+
for other_string in strings[string_index+1:]:
13+
common = find_common_prefix(string, other_string)
14+
if len(common) > len(longest):
15+
longest = common
2416
return longest
2517

2618

@@ -29,4 +21,4 @@ def find_common_prefix(left: str, right: str) -> str:
2921
for i in range(min_length):
3022
if left[i] != right[i]:
3123
return left[:i]
32-
return left[:min_length]
24+
return left[:min_length]

0 commit comments

Comments
 (0)