Longest common prefix: Difference between revisions

Content added Content deleted
(Rather than creating a new string, update its length.)
Line 2,230: Line 2,230:
result = list[0]
result = list[0]
for i in 1..list.high:
for i in 1..list.high:
var newRes = ""
var newLength = 0
for j, c in result:
for j, c in result:
if j >= list[i].len or list[i][j] != c:
if j >= list[i].len or list[i][j] != c:
break
break
newRes.add c
inc newLength
result = move(newRes)
result.setLen(newLength)


proc test(list: varargs[string]) =
proc test(list: varargs[string]) =