We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 01e2c72 commit 863555aCopy full SHA for 863555a
Sprint-2/improve_with_precomputing/common_prefix/common_prefix.py
@@ -10,12 +10,12 @@ def find_longest_common_prefix(strings: List[str]):
10
if len(strings) < 2:
11
return ""
12
# reducing comparison by sorting places strings with similar prefixes next to each other...
13
- strings.sort()
+ sorted_strings = sorted(strings)
14
15
longest = ""
16
- for i in range(len(strings) - 1):
+ for i in range(len(sorted_strings) - 1):
17
# compares only adjacent strings after sorting
18
- common = find_common_prefix(strings[i], strings[i + 1])
+ common = find_common_prefix(sorted_strings[i], sorted_strings[i + 1])
19
if len(common) > len(longest):
20
longest = common
21
return longest
0 commit comments