748
правок
Изменения
→Псевдокод
===Псевдокод===
'''int[]''' buildZFunctionFromPrefixFunction(P : '''int'''[n]) '''int''' n = P.length
'''int'''[] Z = '''int'''[n]
'''for''' i = 1 '''to''' n - 1
Z[i - P[i] + 1] = P[i]
Z[0] = n
'''int''' ti = 1 '''forwhile''' i = 1 < n '''toint''' n - 1 t = i
'''if''' Z[i] > 0
'''for''' j = 1 '''to''' Z[i] - 1
Z[i + j] = min(Z[j], Z[i] - j)
t = i + j
i = t+ 1
'''return''' Z