Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
# Longest common substring.
|
||||
|
||||
import sequtils
|
||||
|
||||
func lcs(a, b: string): string =
|
||||
var lengths = newSeqWith(a.len, newSeq[int](b.len))
|
||||
var greatestLength = 0
|
||||
for i, x in a:
|
||||
for j, y in b:
|
||||
if x == y:
|
||||
lengths[i][j] = if i == 0 or j == 0: 1 else: lengths[i - 1][j - 1] + 1
|
||||
if lengths[i][j] > greatestLength:
|
||||
greatestLength = lengths[i][j]
|
||||
result = a[(i - greatestLength + 1)..i]
|
||||
|
||||
echo lcs("thisisatest", "testing123testing")
|
||||
Loading…
Add table
Add a link
Reference in a new issue