You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Strings.longestCommonSubstring gives incorrect results if the first string is shorter than the second one, because it only scans until the length of the first string:
Strings.longestCommonSubstring gives incorrect results if the first string is shorter than the second one, because it only scans until the length of the first string:
object Strings {
...
def longestCommonSubstring(a: String, b: String) : String = {
def loop(m: Map[(Int, Int), Int], bestIndices: List[Int], i: Int, j: Int) : String = {
if (i > a.length) {
b.substring(bestIndices(1) - m((bestIndices(0),bestIndices(1))), bestIndices(1))
...
Doesn't work:
scala> val lcs = Strings.longestCommonSubstring("the price Is right", "right on!")
lcs: String = ri
Works correctly:
scala> val lcs = Strings.longestCommonSubstring("right on!", "the price is right")
lcs: String = right
The text was updated successfully, but these errors were encountered: