Skip to content

Commit 8a9a20e

Browse files
authored
Create Maximum Common Substring
1 parent 041b5e1 commit 8a9a20e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Given two strings, write a function max_common_substring that finds the longest common substring between the input strings.
2+
3+
A substring is a contiguous sequence of characters within a string. If there is no common substring, your function should return an empty string.
4+
-------------------------------------------------------------------------------------------------------------------------------------------------------------
5+
def max_common_substring(str1, str2):
6+
res = ''
7+
start = 0
8+
for i in range(len(str1)+1):
9+
cur = str1[start:i]
10+
if cur in str2:
11+
if len(cur) > len(res):
12+
res = cur
13+
else:
14+
start+=1
15+
return res

0 commit comments

Comments
 (0)