RosettaCodeData/Task/Longest-common-substring/Julia/longest-common-substring.jl
2024-10-16 18:07:41 -07:00

15 lines
400 B
Julia

function lcs(s1::AbstractString, s2::AbstractString)::String
l, r, sub_len = 1, 0, 0
for i in eachindex(s1)
for j in i:length(s1)
contains(s2, SubString(s1, i, j)) || break
if sub_len j - i
l, r = i, j
sub_len = j - i
end
end
end
return s1[l:r]
end
@show lcs("thisisatest", "testing123testing")