Solution Review: Longest Common Substring
In this lesson, we will look at different strategies to solve the longest common substring problem.
We'll cover the following...
We'll cover the following...
Solution 1: Simple recursion #
Explanation
Let’s look at this problem on a smaller scale. We are comparing each character one by one with the other string. There can be three possibilities for i character of str1 and j character of str2. If both characters match, these could be part of a common substring meaning we should count this length (lines 6-7). In the case that these characters do not match, we could have two further possibilities:
icharacter might match with(j+1)character.jcharacter might match with(i+1)