Fix off-by-one error in LCS calculation

This commit is contained in:
Andy Stewart
2019-09-24 17:10:26 +01:00
parent d2796a277e
commit ccd4972d23
2 changed files with 3 additions and 2 deletions

View File

@@ -135,11 +135,11 @@ function! s:lcs(s1, s2)
for i in range(1, len(a:s1))
for j in range(1, len(a:s2))
if a:s1[i] ==# a:s2[j]
if a:s1[i-1] ==# a:s2[j-1]
let matrix[i][j] = 1 + matrix[i-1][j-1]
if matrix[i][j] > maxlength
let maxlength = matrix[i][j]
let endindex = i
let endindex = i - 1
endif
endif
endfor