L79 Longest Common SubString
Given two strings, find the longest common substring.
Return the length of it.
Notice
The characters in substring should occur continuously in original string. This is different with subsequence.
Example
Given A ="ABCD"
, B ="CBCE"
, return2
.
O(n x m) time and memory.
跟上一题L77的做法基本一样,只是这里要求substring,连续的,当我们发现两个串现在的char不一样时,我们把dp设为0.而且还得用一个max边找边记录。因为结果不一定在最后。
Last updated