初始化整形数组p[1057],整形变量ci,rei=0 //palindrome,central,right endpoint len=INITIALIZE(s,vs); for i=1 to len-1 if i<rei p[i]=min(p[2*ci-i],rei-i) else p[i]=1 while vs[i-p[i]]==vs[i+p[i]] p[i]=p[i]+1 if rei<i+p[i] ci=i rei=i+p[i] maxlen=max(maxlen,p[i-1]) return maxlen
INITIALIZE(S,VS)
1 2 3 4 5 6 7 8 9
len=s.length vs[0]='@' vs[1]='!' for j=2 i=0 to len-1 vs[j]=s[i] j=j+1 vs[j]='!' j=j+1 return j